Skip to content

perf(native): drop redundant useState hook in useCssElement - #602

Merged
danstepanov merged 1 commit into
nativewind:mainfrom
sammoore:perf/use-css-element-skip-use-state
Dec 2, 2026
Merged

danstepanov merged 1 commit into
nativewind:mainfrom
sammoore:perf/use-css-element-skip-use-state

Conversation

@sammoore

@sammoore sammoore commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The useState hook, which was essentially there to cache the result of mappingToConfig, is now redundant; mappingToConfig memoizes its results since #568 was merged.

Benchmark (0b21428 → bb60058)

Measured on a physical iPhone 12 Pro Max (iOS Release build, production Hermes .hbc, 1,000 items / 2,003 views, 4 interleaved ABBA rounds × 5 runs, 3 memory runs).

Scenario Frame Δ JS Δ
remount -1.2% -6.9%
remount, stable inline style -5.4% -6.1%
rerender, same props -2.0% -5.2%
rerender, new inline style -0.6% -1.6%
remount, wrapped without classes -9.1% -3.3%
remount, raw react-native (control) -0.1% -1.7%
mount, shared className +1.0% -1.7%
mount, unique className strings -0.5% -4.2%
mount, unique rule sets, repeat +0.5% -0.8%
mount, unique rule sets, first time +0.3% -0.8%
rerender, className toggles +1.0% -0.2%
mount, active: pseudo-class +0.7% -1.0%
mount, media query +1.2% -1.8%
mount, themed axis border colour +0.1% -4.7%
theme change, :root prefers-color-scheme +1.0% -2.5%
theme change, dark: utilities -8.4% -2.8%
theme change, vars() provider -7.5% -1.7%
theme change, VariableContextProvider +0.4% -0.0%
memory, mounted tree (JS heap / OS) -4.3% (12.5 → 11.9 MiB) -5.6% (138.6 → 130.8 MiB)
memory, raw react-native (control) +0.0% (3.4 → 3.4 MiB) -0.0% (236.5 → 236.4 MiB)

@danstepanov
danstepanov force-pushed the perf/use-css-element-skip-use-state branch from bb60058 to 1432fc8 Compare December 2, 2026 19:21
@danstepanov
danstepanov merged commit 0dacc4b into nativewind:main Dec 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants