Repository navigation
Skip the container scan on consecutive blank lines - #1148
Merged
Merged
Conversation
This commit accomplishes the same thing as <#1145>, but without allocating more memory. The fix is shamelessly "borrowed" from <commonmark/cmark#520>, which fixes the same bug. Deeply nested lists followed by blank lines parsed in quadratic time. `scan_containers` runs once per line and walked the whole spine, and on a blank line every list item matched without consuming anything, so each blank line cost time proportional to the nesting depth. List levels cost two bytes each and blank lines one, so a small input goes a long way. Before ------ ```console % python3 -c 'N=800; print("- " * N + "a" + "\n" * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.01s user 0.01s system 16% cpu 0.076 total % python3 -c 'N=8_000; print("- " * N + "a" + "\n" * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.34s user 0.00s system 88% cpu 0.390 total % python3 -c 'N=80_000; print("- " * N + "a" + "\n" * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 34.42s user 0.18s system 99% cpu 34.770 total % python3 -c 'N=800; print(">" + "- " * N + "a" + "\n> " * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.01s user 0.00s system 15% cpu 0.073 total % python3 -c 'N=8_000; print(">" + "- " * N + "a" + "\n> " * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.34s user 0.00s system 87% cpu 0.386 total % python3 -c 'N=80_000; print(">" + "- " * N + "a" + "\n> " * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 33.39s user 0.09s system 99% cpu 33.562 total ``` After ----- ```console % python3 -c 'N=800; print("- " * N + "a" + "\n" * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.00s user 0.01s system 7% cpu 0.113 total % python3 -c 'N=8_000; print("- " * N + "a" + "\n" * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.00s user 0.01s system 11% cpu 0.077 total % python3 -c 'N=80_000; print("- " * N + "a" + "\n" * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.01s user 0.01s system 21% cpu 0.087 total % python3 -c 'N=800; print(">" + "- " * N + "a" + "\n> " * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.00s user 0.00s system 7% cpu 0.075 total % python3 -c 'N=8_000; print(">" + "- " * N + "a" + "\n> " * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.00s user 0.01s system 13% cpu 0.075 total % python3 -c 'N=80_000; print(">" + "- " * N + "a" + "\n> " * N * 2)' | time ./target/release/pulldown-cmark > /dev/null ./target/release/pulldown-cmark > /dev/null 0.01s user 0.01s system 28% cpu 0.067 total ```
notriddle
force-pushed
the
blank-line-containers
branch
3 times, most recently
from
September 27, 2026 04:22
f94c0cd to
9866ec9
Compare
Benchmark from <https://github.com/pulldown-cmark/pulldown-cmark/pull/1145/changes#diff-084cafcc79a67fda4b29beb072072c716e36751faa17cd810ede7f5848b1612d> Also ported to run in the dos-fuzzer as a regression test.
notriddle
force-pushed
the
blank-line-containers
branch
from
September 27, 2026 04:27
9866ec9 to
366a6e5
Compare
Merged
Martin1887
added a commit
that referenced
this pull request
Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit accomplishes the same thing as #1145, but without allocating more memory. The fix is shamelessly "borrowed" from commonmark/cmark#520, which fixes the same bug.
Deeply nested lists followed by blank lines parsed in quadratic time.
scan_containersruns once per line and walked the whole spine, and on a blank line every list item matched without consuming anything, so each blank line cost time proportional to the nesting depth. List levels cost two bytes each and blank lines one, so a small input goes a long way.Before
After