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

perf(SSR): remove regexp in function escapeHtml #31706

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ShuiRuTian
Copy link

@ShuiRuTian ShuiRuTian commented Dec 9, 2024

Summary

Regular expression is slow, removing them in escapeHtml should make things faster

I did similar change in vue at first: vuejs/core#12507 (comment)

Then I took a look at react and found vue copied react's implementation, then why not let react have this improvement too?

How did you test this change?

Some simple benchmark by me and @Justineo

https://jsbench.me/rqm4ehfndc/1, shows for simple cases, it's 2x~3x faster
https://jsben.ch/pbGau, shows for random string, it's 1.1x faster

Also cc @aickin, who refactor escapeHtml 8 years ago, maybe you might have interest in this PR too

Copy link

vercel bot commented Dec 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2024 7:01am

@facebook-github-bot
Copy link

Hi @ShuiRuTian!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@ShuiRuTian ShuiRuTian changed the title perf: remove regexp in function escapeHtml perf(SSR): remove regexp in function escapeHtml Dec 10, 2024
@ShuiRuTian
Copy link
Author

Ping members working in Vercel, could you please review this PR?

@acdlite @gnoff @sebmarkbage @eps1lon

Considered that next.js is a SSR-first framework(correct me If I am wrong...), this should be a good micro optimization for free.

@react-sizebot
Copy link

The size diff is too large to display in a single comment. The GitHub action for this pull request contains an artifact called 'sizebot-message.md' with the full message.

Generated by 🚫 dangerJS against 4828172

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

Successfully merging this pull request may close these issues.

3 participants