Repository navigation
[markdown] Fix quadratic parsing of consecutive link reference definitions - #2662
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request addresses a performance issue where parsing consecutive link reference definitions took quadratic time. Instead of pre-consuming and joining all remaining lines in a block, LinkParser now directly wraps BlockParser and lazily consumes lines only as needed for a single definition, retreating the parser if validation fails. A regression test has been added to verify that parsing 5,000 consecutive link reference definitions is efficient. There are no review comments, and I have no additional feedback to provide.
copybara-service Bot
pushed a commit
to dart-lang/sdk
that referenced
this pull request
Oct 15, 2026
Revisions updated by `dart tools/rev_sdk_deps.dart`. native is rolled separately in https://dart-review.googlesource.com/c/sdk/+/563524. http (https://github.com/dart-lang/http/compare/23f8574..7d7aae2): 7d7aae2 Mon Oct 12 20:39:25 2026 -0700 Kevin Moore Clean up dependencies and expand Node and Wasm test coverage (dart-lang/http#1903) ab986ad Mon Oct 12 18:59:24 2026 -0700 Kevin Moore fix(http_parser): fix chunked size overflow and MediaType.toString quoting (dart-lang/http#2001) cb8113b Mon Oct 12 17:35:26 2026 -0700 Kevin Moore docs(http2): move post-3.1.0 security entries to 3.2.0-wip (dart-lang/http#2022) test (https://github.com/dart-lang/test/compare/30acb69..9bf69a8): 9bf69a88 Tue Oct 13 14:33:18 2026 -0700 Nate Bosch Reject asynchronous matchers inside isNot and anyOf (dart-lang/test#2792) tools (https://github.com/dart-lang/tools/compare/2b54c71..350bde5): 350bde54f Tue Oct 13 08:22:26 2026 -0700 Kevin Moore chore(coverage): prepare for v1.16.0 release (dart-lang/tools#2643) a55965844 Tue Oct 13 13:29:52 2026 +0200 Sigurd Meldgaard [markdown] Fix quadratic parsing of consecutive link reference definitions (dart-lang/tools#2662) [email protected] TEST=ci Change-Id: I1065854cfbaf71ebb7a097d89f28902394a80c2e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/563365 Commit-Queue: Nate Bosch <[email protected]> Reviewed-by: Brian Quinlan <[email protected]>
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.
LinkReferenceDefinitionSyntax.canEndBlockisfalse(link reference definitions cannot interrupt a paragraph), soBlockSyntax.isAtBlockEnd(parser)does not stop at subsequent link reference definitions.Previously,$N$ consecutive link reference definitions (such as the $O(N^2)$ lines.
LinkReferenceDefinitionSyntax.parsegreedily consumed all remaining lines until the end of the block, joined them with\n, parsed a single definition, splitsource.substring(pos).split('\n')to count unconsumed lines, and calledparser.retreatBy(unconsumedLines). For[#1]..[#N]block at the bottom of large changelogs), this joined and splitInstead, pass
BlockParserdirectly intoLinkParserand start with only the current line, advancing through additional lines fromBlockParseron demand only when a link label, destination, or title spans across a newline, and retreatingBlockParserif the definition or a multiline title fails.