-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: hoist regex patterns #18438
base: main
Are you sure you want to change the base?
perf: hoist regex patterns #18438
Conversation
@patak-dev Hey! Apologies for the mention, but I wanted to ask which areas you'd like me to leave as is? I see some possible changes in create-vite, rollup.config.ts, and other, "normal" files in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one looks good to me, thanks! If you see other similar changes, you can send other PRs to review them separatedly.
Can I combine them all in here so it could be merged at once? I found many places that can benefit from it, just wanted to know if any parts are not to be altered before I accidentally alter them |
Ya, that is ok too. Thanks! |
Nice 👍 I'm curious about how much it affects large builds. Peak memory usage reduction would be awesome |
Description
Hoisting regex patterns from loops/hot code paths provides both better performance and better memory efficiency, both of which are especially invaluable for resource-constrained environments.
By reusing the hoisted pattern, the engine doesn't need to waste time on recompiling the pattern, thus performing better, and doesn't need to waste resources on local object creation and GC cycles, thus being more efficient.
The benchmark and memory profiling (of the benchmark) is taken from nuxt/nuxt#29620
Each part was ran separately to prevent any sort of inline cache from altering the results
Results:
Browser:
Node:
It also shows a 50% decrease in memory usage in this simple benchmark alone, and has been tested using a memory profiler: