Repository navigation
Conversation
buildScopedVariablesContext sorts the merged variables with localeCompare to build the cache key. On Hermes for Android, each localeCompare call creates and frees a Java Collator through JNI, so a ScopedVariables with 60 variables made 354 calls and took about 10 ms to build on low-end Android devices. The key only needs the same order every time, and CSS custom property names are ASCII, so sort by code unit instead. The key's text can change order for names that differ in case, but it stays the same for the same variables, and only the native style cache reads it. On the same devices the build dropped to about 0.4 ms.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Cache key sorting and validation packages/uniwind/src/components/ScopedVariables/utils.ts, packages/uniwind/tests/native/components/scoped-variables.test.tsx |
The cache key sorts entries using direct code-unit comparisons. The test checks equivalent maps with different insertion orders and verifies that localeCompare is not called. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Refactor
Suggested reviewers: brentlok
Merge Risk: 
Minimal · up to b14bc
-
The cache-key ordering change has no identified merge-blocking issue; merge after normal checks.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
[Low impact] The PR appears safe to merge. SummaryReplaces
Reviews (1) · Last reviewed commit: "perf: sort scoped variable cache keys wi..." · Reviewed by Greptile |
|
🚀 This pull request is included in v1.13.1. See Release v1.13.1 for release notes. |
buildScopedVariablesContextsorts the merged variables withlocaleCompareto build the native style cache key. On Hermes for Android, everylocaleComparecall creates and frees a JavaCollatorthrough JNI, so this sort costs far more than it looks.The key only needs the same order every time, and CSS custom property names are ASCII, so this sorts by code unit instead. The key's text can order names that differ in case differently from before, but the same variables always give the same key, and only the in-memory style cache reads it.
Measured
Release Hermes build on two low-end Android devices,
ScopedVariablescontext with 60 variables (an app theme plus a component's own):localeComparecalls per buildOne
localeComparetook 73-82 µs there, against 0.3 µs for a code-unit comparison. In an isolated benchmark the sort alone took 23-26 ms per build, and 47 ms on the little cores.Tests
localeCompare. It fails onmainin both Jest projects and passes with this change.apps/expo-examplefor iOS, Android and web, builtapps/vite-example, and bundledapps/bare.Summary by CodeRabbit