Repository navigation
Babel preset: Stop lowering Unicode regexes for Hermes V1 - #59580
Merged
Merged
Conversation
The Hermes profiles still run `@babel/plugin-transform-unicode-regex`, which rewrites every `u`-flag regex into one without the flag. For Unicode property escapes, that means expanding a `\p{L}` into kilobytes of explicit ranges and surrogate pairs. Hermes V1 compiles `u` regexes natively, so the expansion only costs bytecode size, memory and speed:
- Bytecode: -64 KB (-0.67%) in a 9.5 MB RN 0.88 test app, and -75 KB (-0.30%) in Mattermost mobile. Hermes keeps each regex's source text for `RegExp.prototype.source`, so an expanded pattern is paid for in string storage as well as in regex bytecode.
- Memory: -584 KB of live JS heap and -205 KB of native regex bytecode (copied into every `RegExp` object) after loading highlight.js, fuse.js, path-to-regexp and zod, which build regexes from `\p{...}` classes.
- Speed: regex-bound library code is faster natively, by up to 17% (fuse.js index build -16%, zod's `unicodeEmail` -13%, first highlight.js highlight 12.5 ms -> 8 ms). The one slower case was path-to-regexp route compilation, at +1.0-1.3%.
Every `\p{...}` spelling the transform accepts (1,647 property names, values and aliases from `regenerate-unicode-properties`) compiles with the hermesc that RN 0.88 ships (260318099.0.4) and runs in Hermes V1. Natively compiled property escapes follow the engine's Unicode data rather than Babel's, so results can differ only for characters assigned in one Unicode version and not the other. The `hermes-legacy` and `default` profiles keep the transform.
Full analysis: https://robhogan.github.io/reports/react-native-babel-preset-hbc-size/
Changelog: [General][Changed] - Babel preset: Hermes V1 profiles no longer lower `u`-flag regexes, which Hermes compiles natively
javache
approved these changes
Oct 28, 2026
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D128117415. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The Hermes profiles still run
@babel/plugin-transform-unicode-regex, which rewrites everyu-flag regex into one without the flag. For Unicode property escapes, that means expanding a\p{L}into kilobytes of explicit ranges and surrogate pairs. Hermes V1 compilesuregexes natively, so the expansion only costs bytecode size, memory and speed.The
hermes-legacyanddefault(JSC) profiles keep the transform.Impact
Entirely dependent on use of these regexs, many apps won't use them, some libraries use them extensively. The snapshot changes in this PR illustrate the difference.
RegExp.prototype.source, so an expanded pattern is paid for in string storage as well as in regex bytecode.RegExpobject) after loading highlight.js, fuse.js, path-to-regexp and zod, which build regexes from\p{...}classes.unicodeEmail-13%, first highlight.js highlight 12.5 ms -> 8 ms). The one slower case was path-to-regexp route compilation, at +1.0-1.3%.Test plan
\p{...}spelling the transform accepts (1,647 property names, values and aliases fromregenerate-unicode-properties) compiles and runs in Hermes active stable (260318099.0.4) .Note: natively compiled property escapes follow the engine's Unicode data rather than Babel's, so results can differ only for characters assigned in one Unicode version and not the other.
Changelog
[General][Changed] - Babel preset: Hermes V1 profiles no longer lower
u-flag regexes, which Hermes compiles natively