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

Performance improvements! #192

Merged
merged 2 commits into from
Mar 25, 2021
Merged

Conversation

developit
Copy link
Member

@developit developit commented Mar 20, 2021

Screen Shot 2021-03-19 at 8 25 11 PM

Some benchmarks, for reference:
https://esbench.com/bench/5f88af6cb4632100a7dcd414

export function encodeEntities(s) {
if (typeof s !== 'string') s = String(s);
return s.replace(HTML_ENTITY_REG, replaceTag);
return String(s)
Copy link
Member

@marvinhagemeister marvinhagemeister Mar 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment to summarize our findings from yesterdays quick benchmarking session and why we're going with the replace variant again.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always felt that this change was suspicious and could be the root cause of the performance issues I reported previously for versions after 5.1.2.

I plan to deploy a test release next Monday and roll back this part of the change separately from the 5.1.16 version of the code to see if there are still performance issues.

Copy link

@JimLiu JimLiu Mar 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@developit developit Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JimLiu - that benchmark website produces statistically meaningless results. It's not open source (which is a problem), but I looked at the implementation and it's effectively running benchmarks in a tight loop: while(performance.now()-start < 5000) test(). This makes the order of benchmarks matter, and allows the JS VM to perform cross-benchmark optimizations that can only happen in the specific case of while(1) test() and never in real code.

The only current benchmarking website that produces statistically meaningful results is ESbench (disclaimer: I maintain it). The reason for this is because it uses the same Benchmark.js (the library that powered JSPerf, built by Matthias Bynens from the V8 team). Benchmark.js performs JIT warmup runs, encapsulates benchmarks in functions that prevent synthetic VM optimizations (like hoisting/inlining of benchmark code), and returns median values with standard deviation.

Here's the benchmarks we use for encodeEntities on ESBench:
https://esbench.com/bench/5f88af6cb4632100a7dcd414

Screen Shot 2021-03-25 at 11 45 36 AM

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Left a few minor comments. Let me know what you think 👍

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.

3 participants