showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.1k stars 1.57k forks source link

Performance improvement for large texts with many HTML spans #994

Open dpoetzsch opened 6 months ago

dpoetzsch commented 6 months ago

tl;dr;

This PR implements a huge performance improvement for large files with many html spans (e.g. links).

Full version

We recently had a case of a large markdown file (~2MB) including a table with ~4000 links. This took about 15-20s to process.

This PR fixes that by massively reducing the amount of string copies.

I added a performance test case that shows a speed improvement of about 2000%.

If this gets accepted, it'd be nice to also backport it to 2.x.x (which is easily done by rebasing this branch on 2.1.0 - no conflicts involved).

codeclimate[bot] commented 6 months ago

Code Climate has analyzed commit 64835648 and detected 0 issues on this pull request.

View more on Code Climate.