Skip to content

Conversation

@kivikakk
Copy link
Owner

@kivikakk kivikakk commented Nov 8, 2025

The status quo is that cm will buffer all output in self.output, which gets written out all-at-once to the provided fmt::Write.

If we're not wrapping (options.render.width > 0), and we're not using the experimental escape minimizer (GH-523), we don't need to buffer output at all.

If we're wrapping, we need to buffer at most until a line break or wrapping event occurs.

If we're using the experimental escape minimizer, we still have to buffer everything.

It was annoying to move from doing things this way (made easy by the reference C implementation) because we need to know some properties of the last few bytes written out; whether up to the last two bytes were linefeeds, and whether the last byte was an ASCII digit. We keep a window of the last two bytes written out to furnish this.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

Command Mean [ms] Min [ms] Max [ms] Relative
./bench.sh ./comrak-3bdc700 104.4 ± 1.3 102.1 107.7 1.76 ± 0.06
./bench.sh ./comrak-main 103.9 ± 1.1 101.4 106.5 1.76 ± 0.06
./bench.sh ./pulldown-cmark 59.2 ± 1.9 57.8 70.7 1.00
./bench.sh ./cmark-gfm 92.0 ± 6.9 81.8 104.2 1.55 ± 0.13
./bench.sh ./markdown-it 260.6 ± 3.0 253.9 268.2 4.40 ± 0.15

Run on Sat Nov 8 12:48:21 UTC 2025

@kivikakk kivikakk changed the title don't buffer commonmark output when unnecessary. don't buffer commonmark output unless necessary. Nov 8, 2025
@kivikakk kivikakk merged commit bca6968 into main Nov 9, 2025
44 checks passed
@kivikakk kivikakk deleted the push-kvzwlmmuoqoq branch November 9, 2025 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants