Why instantiate a new markdown renderer for each file processed?
Closed this issue · 3 comments
I assume the rendering process would execute much faster if the Markdown parser was configured once, then used repeatedly. Currently, for each file processed, the renderer is instantiated, all the plugins loaded, and configured, and finally, the text is processed.
Is there a reason for this? Perhaps the plugins or the markdown renderer is stateful?
I forked the code and did a quick hack to instantiate/configure the markdown parser only once. Seems to result in the same output for my limited tests.
I have 27 markdown files in my source folder.
Current code: 400ms
Optimized code: 320ms
Not as impressive as I expected the performance difference to be. I guess most of the time is spent in the initial require() commands to load/parse each plugin. Once those are cached, the rest of the overhead in configuring each plugin is minimal.
May I know what did you change to make this renderer only instantiate once?
May I know what did you change to make this renderer only instantiate once?
@curbengh As you can see, we require markdown-it
whenever the renderer function is called:
We also new
a markdown-it
instance whenever the renderer function is called:
hexo-renderer-markdown-it/lib/renderer.js
Line 16 in a4f2be7
We could lift them to the top.