Case Study: Optimizing CommonMark Markdown Parser with Blackfire.io
As you may know, I am the author and maintainer of the PHP League's CommonMark Markdown parser. This project has three primary goals:
fully support the entire CommonMark spec
match the behavior of the JS reference implementation
be well-written and super-extensible so that others can add their own functionality.
This last goal is perhaps the most challenging, especially from a performance perspective. Other popular Markdown parsers are built using single classes with massive regex functions. As you can see from this benchmark, it makes them lightning fast:
Library
Avg. Parse Time
File/Class Count
Parsedown 1.6.0
2 ms
1
PHP Markdown 1.5.0
4 ms
4
PHP Markdown Extra 1.5.0
7 ms
6
CommonMark 0.12.0
46 ms
117
Unfortunately, because of the tightly-coupled design and overall architecture, it's dif...