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

Optimize tight/loose list parsing (new algorithm from commonmark-java) #151

Open
robinst opened this issue Nov 9, 2018 · 0 comments
Open

Comments

@robinst
Copy link
Contributor

robinst commented Nov 9, 2018

Hey! The commonmark-java implementation was using the same algorithm as commonmark.js and cmark for determining whether a list is tight or loose. I recently re-implemented it because it showed up in a profiling session.

The results for the new algorithm are pretty good: a 10% performance improvement! See details here: commonmark/commonmark-java@cfd28fa

I'm opening this issue because you might be interested in porting it back to the reference implementations :). I don't know if the improvement will be as significant, but it's worth a try.

It works like this (but see the commit above for details):

  • In the parser for list items:
    • in continue, remember when there was a blank line (except when a code block is being parsed)
    • in canContain (which is called when a new child will be added), set tight to false if we saw a blank line before
  • In the parser for list blocks:
    • in continue, remember when we had a blank line (and how many lines back it was)
    • in canContain, set tight to false if the previous line was blank

(The new algorithm also feels simpler, hopefully there's no holes in it. It passes all the spec tests and some extra ones.)

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

No branches or pull requests

1 participant