perf: Cache parsed box shadow strings - #57968
Open
ya-nsh wants to merge 1 commit into
Open
Conversation
ya-nsh
force-pushed
the
perf/cache-box-shadow-parsing
branch
from
August 15, 2026 19:21
940006d to
b48379e
Compare
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:
processBoxShadowreparses string values every time style processing runs, even when the same static shadow is shared by many views.This adds a 1024-entry LRU cache for string inputs. A value is admitted after its second use so one-off dynamic strings do not pay the allocation cost of cloning a result. Cached arrays and entries are copied before they are returned, which preserves the existing mutation behavior. Array inputs continue through the existing uncached path.
I also added a Fantom benchmark for repeated and unique string inputs. A local release Metro bundle run on Node 22.22.1, pinned to one CPU, produced these median times over 25 samples:
The repeated cases were 27.0x and 31.1x faster. The unique case was 22.3% slower from bounded cache bookkeeping, without the extra result clone that a first-use admission policy would require.
Changelog:
[GENERAL] [CHANGED] - Cache repeated CSS box shadow processing
Test Plan:
yarn test packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-test.js --runInBand(4 tests passed)yarn flow-check --show-all-errors(0 errors)yarn eslint packages/react-native/Libraries/StyleSheet/processBoxShadow.js packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-test.js packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-benchmark-itest.jsnode node_modules/prettier/bin/prettier.cjs --check packages/react-native/Libraries/StyleSheet/processBoxShadow.js packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-test.js packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-benchmark-itest.jsgit diff --check