Skip to content

Optimize nested style array flattening#57200

Closed
tarikfp wants to merge 1 commit into
react:mainfrom
tarikfp:codex/optimize-style-flatten
Closed

Optimize nested style array flattening#57200
tarikfp wants to merge 1 commit into
react:mainfrom
tarikfp:codex/optimize-style-flatten

Conversation

@tarikfp

@tarikfp tarikfp commented Jun 14, 2026

Copy link
Copy Markdown

Summary

Flatten nested style arrays directly into the final result object instead of recursively allocating intermediate flattened objects and copying their keys again.

This preserves the existing public behavior:

  • non-array style objects still return by reference
  • array inputs still allocate a fresh flattened object
  • merge order for nested arrays is unchanged

Nested style arrays can show up when style props are composed across component boundaries. Avoiding the intermediate object reduces allocation and duplicate key-copy work for those paths.

Local benchmark

Node v24.15.0 side-by-side microbenchmark, 9-run median, 5,000,000 iterations per run:

Case Before After Delta
array with one style 71.14 ns/op 72.52 ns/op -1.9%
array with one effective style 84.39 ns/op 76.33 ns/op 9.5% faster
nested array with one effective style 163.90 ns/op 83.43 ns/op 49.1% faster
nested array with merged styles 254.62 ns/op 161.43 ns/op 36.6% faster
array with merged styles 129.32 ns/op 119.59 ns/op 7.5% faster

Changelog:

[GENERAL][CHANGED] - Improve flattening performance for nested style arrays.

Test Plan:

  • ./node_modules/.bin/eslint --max-warnings 0 packages/react-native/Libraries/StyleSheet/flattenStyle.js packages/react-native/Libraries/StyleSheet/__tests__/flattenStyle-test.js packages/react-native/Libraries/StyleSheet/__tests__/flattenStyle-benchmark-itest.js
  • yarn jest packages/react-native/Libraries/StyleSheet/__tests__/flattenStyle-test.js --runInBand
  • yarn flow check
  • git diff --check
  • yarn fantom packages/react-native/Libraries/StyleSheet/__tests__/flattenStyle-benchmark-itest.js --benchmarks exits successfully in OSS, but the benchmark suite is skipped by the OSS Fantom optimized-mode gate.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 14, 2026
@tarikfp tarikfp closed this by deleting the head repository Jun 15, 2026
@tarikfp tarikfp changed the title [codex] Optimize nested style array flattening Optimize nested style array flattening Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant