Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up decoding HTML Entities. #218

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mdevils
Copy link

@mdevils mdevils commented Mar 27, 2021

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)

@jgm
Copy link
Member

jgm commented Mar 29, 2021

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.

@mdevils
Copy link
Author

mdevils commented Mar 29, 2021

@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 mdevils force-pushed the speed-up-decoding-entities branch from c38e7fe to 45e65bf Compare March 29, 2021 15:27
@jgm
Copy link
Member

jgm commented Mar 29, 2021

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.

@mdevils
Copy link
Author

mdevils commented Mar 29, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants