dart-lang / markdown

A Dart markdown library
https://pub.dev/packages/markdown
BSD 3-Clause "New" or "Revised" License
455 stars 200 forks source link

Unusually long parsing times for not that long documents #579

Open isoos opened 10 months ago

isoos commented 10 months ago

Some long markdown files may take several seconds to parse and process, e.g.: https://raw.githubusercontent.com/Workiva/over_react/master/CHANGELOG.md

Using:

List<m.Node> _parseMarkdownSource(String source) {
  final document = m.Document(
      extensionSet: m.ExtensionSet.gitHubWeb,
      blockSyntaxes: m.ExtensionSet.gitHubWeb.blockSyntaxes);
  final lines = source.replaceAll('\r\n', '\n').split('\n');
  return document.parseLines(lines);
}

It also looks like the parsing time is not linear with the length of the document:

I expected a somewhat linear time to take a 2x document to parse, but apparently it is not that way. Let's explore if this can be improved.

srawlins commented 10 months ago

Interesting analysis, thank you!