Exception flood caused by premature parsing #208
Unanswered
Danielku15
asked this question in
General
Replies: 1 comment
-
|
This is indeed like that, I don’t think it can work some other way. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there.
I am currently troubleshooting some performance problems in building my Docusaurus based website. While investigating I noticed that there was a flood of exceptions thrown in acorn while the MDX files are parsed. Looking up the callstack I noticed something suspicious: Micromark prematurely attempts to parse MDX expressions with acorn whenever it hits a
}character:https://github.com/micromark/micromark-extension-mdx-expression/blob/2891b75ff9e985c6df208a47348e76ced05dbfed/packages/micromark-factory-mdx-expression/dev/index.js#L156-L159
Assume following MDX being parsed:
<Demo attr={[["1}","2}","3}","4}","5}","6}","7}","8}","9}","10}"]]} />On every
}character, it tries to parse the preliminary code with acorn leading to errors here. I added some logging there and this is what I see:For my website with a lot generated reference docs (3228 files) in total, this sums up to 11304 exceptions.
I doubt that this is the intended behavior. The redundant parsing attempts and also the exceptions can lead to quite some performance hit.
A minimal example can be seen here: https://github.com/Danielku15/mdx-parsing This repo parses a MDX input file similar to how Docusaurus does it.
I wonder if there is something that could be improved around this parsing logic to avoid this trial&error parsing approach.
Beta Was this translation helpful? Give feedback.
All reactions