Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of reference definition list parsing #998

Closed

Conversation

RomanHotsiy
Copy link

@RomanHotsiy RomanHotsiy commented Jan 29, 2024

Fixes #996

Looks like the reference definitions cannot interrupted by any of the elements if I read the spec correctly.

None of the tests fail.

By removing the redundant termination logic checks the speed of parsing long list of reference definitions improves dramatically.

~2.5x on the benchmark included in this repo, but in our example where we have 1000 definitions it's almost 20x!

benchmark before

./benchmark/benchmark.mjs block-ref-list
Selected samples: (1 of 28)
 > block-ref-list

Sample: block-ref-list.md (782 bytes)
 > commonmark-reference x 29,907 ops/sec ±0.24% (96 runs sampled)
 > current x 6,429 ops/sec ±0.23% (98 runs sampled)
 > current-commonmark x 7,261 ops/sec ±0.13% (98 runs sampled)
 > markdown-it-2.2.1-commonmark x 36,093 ops/sec ±0.20% (94 runs sampled)
 > marked x 55,087 ops/sec ±2.06% (99 runs sampled)

benchmark after

./benchmark/benchmark.mjs block-ref-list
Selected samples: (1 of 28)
 > block-ref-list

Sample: block-ref-list.md (782 bytes)
 > commonmark-reference x 29,025 ops/sec ±0.50% (94 runs sampled)
 > current x 15,550 ops/sec ±0.35% (94 runs sampled)
 > current-commonmark x 16,762 ops/sec ±0.63% (95 runs sampled)
 > markdown-it-2.2.1-commonmark x 35,562 ops/sec ±0.23% (91 runs sampled)
 > marked x 55,408 ops/sec ±0.18% (98 runs sampled)

@RomanHotsiy
Copy link
Author

oh, it looks like it can be improved more by removing the redundant code in the reference parsing.

I'll adjust it later today.

@rlidwka
Copy link
Member

rlidwka commented Feb 3, 2024

Here's a test which would have different behavior:

[foo]: /url 'title
 - - -
'

[foo]

It was <hr>, now it's a reference link.

@RomanHotsiy
Copy link
Author

Superseded by #1004

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.

Major performance issue when parsing a long list of reference links
2 participants