micromark / micromark-extension-gfm

micromark extension to support GFM (GitHub Flavored Markdown)
https://unifiedjs.com
MIT License
30 stars 2 forks source link

Poor performance with large amounts of text #8

Closed charliematters closed 2 years ago

charliematters commented 2 years ago

Initial checklist

Affected packages and versions

micromark-extension-gfm-table@1.0.5

Link to runnable example

https://github.com/charliematters/gfm-speed-bug

Steps to reproduce

We noticed a slow-down when trying to render large amounts of plain text as Markdown when using the GFM tables plugin. I've written a simple reproduction which should show the differences between performance with the plugin both enabled and disabled. I ran it using node 18 and npm 8.

The input text is the bee movie script (as it's large and contains no complicated syntax), and on my M1 MacBook Pro, adding the plugin takes the time from 30ms to 10,000ms.

This is obviously more noticeable on the end-users computers where we're seeing times in excess of 90s to render mostly plain-text markdown content.

I don't want to disable the plugin, but if there is an obvious fix for this then that would be great!

Expected behavior

Rendering (parsing?) tables shouldn't add a noticeable overhead to execution time

Actual behavior

Rendering time increases greatly when using the micromark-extension-gfm-table plugin

Runtime

Other (please specify in steps to reproduce)

Package manager

Other (please specify in steps to reproduce)

OS

macOS

Build and bundle tools

Other (please specify in steps to reproduce)

github-actions[bot] commented 2 years ago

Hi! Thanks for taking the time to contribute!

Because we treat issues as our backlog, we close duplicates to focus our work and not have to touch the same chunk of code for the same reason multiple times. This is also why we may mark something as duplicate that isn’t an exact duplicate but is closely related.

Thanks, — bb

ChristianMurphy commented 2 years ago

Duplicate of https://github.com/remarkjs/remark/discussions/978

To quote that discussion:

Hey! GFM tables are tough to parse, they are different than other markdown constructs and require looking ahead further. That being said, there are likely things to improve where they are parsed: https://github.com/micromark/micromark-extension-gfm-table. Perhaps you can profile and help there?

You can for example try different versions of micromark-extension-gfm-table and micromark to understand if this is something that was introduced at some point or if it was already present from the start. You can also try different markdown input, to see if the problem might be lines or columns or long cells or what. You can change states to switch to the nok state, to see if that magically solves everything (of course, nok stops parsing, so it also breaks everything).

You can read in particular the Architecture section in the micromark readme for more on how the project works.

source: https://github.com/remarkjs/remark/discussions/978#discussioncomment-2467934

github-actions[bot] commented 2 years ago

Hi team! It seems this post is a duplicate, but hasn’t been marked as such. Please post a comment w/ Duplicate of #123(no final .) to do so. See GH docs for more info.

Thanks, — bb