commonmark.js icon indicating copy to clipboard operation
commonmark.js copied to clipboard

Speed up decoding HTML Entities.

Open mdevils opened this issue 4 years ago • 4 comments

Improve performance by using decodeEntity() from html-entities when decoding entities.

Benchmark results

Before

$ node bench/bench.js bench/samples/inline-entity.md
commonmark.js x 35,682 ops/sec ±1.52% (87 runs sampled)
showdown.js x 7,871 ops/sec ±4.67% (84 runs sampled)
marked.js x 55,382 ops/sec ±1.05% (96 runs sampled)
markdown-it x 41,105 ops/sec ±20.31% (89 runs sampled)

After

$ node bench/bench.js bench/samples/inline-entity.md
commonmark.js x 42,870 ops/sec ±5.41% (83 runs sampled)
showdown.js x 8,168 ops/sec ±1.11% (89 runs sampled)
marked.js x 51,986 ops/sec ±4.46% (86 runs sampled)
markdown-it x 47,063 ops/sec ±3.06% (94 runs sampled)

mdevils avatar Mar 27 '21 17:03 mdevils

Thanks! I like the speed improvement, but I'm less sure about other tradeoffs in switching from entities to html-entities. Overall quality of the libraries, degree of usage, unpacked size? I'm not a JavaScript person so hopefully others can also weigh in on this.

jgm avatar Mar 29 '21 14:03 jgm

@jgm html-entities is widely used and is focused on performance, has around 10kk installations per week according to https://www.npmjs.com/package/html-entities. html-entities has both higher performance and loading speed compared to entities.

mdevils avatar Mar 29 '21 15:03 mdevils

Yes, but entities has 27k installations per week, so it's the more widely used library, and it reports a much smaller unpacked size (57k vs 161k). That's why the decision doesn't seem obvious to me.

jgm avatar Mar 29 '21 15:03 jgm

@jgm the latest html-entities is 99.5 kB :)

mdevils avatar Mar 29 '21 15:03 mdevils