nmark icon indicating copy to clipboard operation
nmark copied to clipboard

Improved performance a bit

Open Yardanico opened this issue 2 years ago • 1 comments

Hello! I like that you tried to make a fast Markdown parser, so I spent some time figuring out if I can speed up anything. With these changes, I got speedups of around ~10%.

I'll explain some changes as GitHub comments.

Also, there's one more optimization that alone can bring around ~10% more performance, but sadly it'll make compile-time much slower: Basically, since you do

  if line.startsWith(reHtmlBlock1Begins) or
    line.startsWith(reHtmlBlock2Begins) or
    line.startsWith(reHtmlBlock3Begins) or
    line.startsWith(reHtmlBlock4Begins) or
    line.startsWith(reHtmlBlock5Begins) or
    line.startsWith(reHtmlBlock6Begins) or
    line.startsWith(reHtmlBlock7Begins1) or
    line.startsWith(reHtmlBlock7Begins2) or

in 4 different places we can create one "big" regex that combines all of these, and then change the code to use it instead. Maybe there's another way of combining multiple regexes without making compile-time much worse, but I'm not sure.

Yardanico avatar Dec 04 '21 09:12 Yardanico

Looks like the parseInline change is much more invasive than I thought - it makes nmark fail around 100 more commonmark tests, so converted the PR into a draft for now.

Yardanico avatar Dec 04 '21 10:12 Yardanico