Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: