Repository navigation
perf: avoid calculating styles/rules twice on first mount - #466
Conversation
|
Are there still to do items for this? Curious why it's a draft PR. |
|
@danstepanov can you run GH/CI workflows on this? |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LLM summary from original session (benchmark values not 100% accurate -- improvement closer to 33%)Fix NativeWind 5 rc.0 performance regression: optimize fresh-mount reconnectProblemNativeWind 5 (react-native-css rc.0) is ~42% slower than NativeWind 4 in bulk remount benchmarks (~426ms vs ~200ms). PR #451's unconditional reconnect pattern runs a full Root CauseThe initializer cleanup (introduced to handle StrictMode double-invocation) detaches all subscriptions. The commit effect then unconditionally re-runs both effects ( Solution (2 commits)Commit 1:
|
This is good to merge. |
Overview
After the Expo 57 updates in #451, Nativewind v5 performs 33% slower per Uniwind's benchmark. Based on those changes, we now run
stylesandrulesupdates twice: a second, new time in auseEffect(after the component mounts). This is in order to satisfy Strict Mode guarantees (i.e. effects getting destroyed and then recreated in React dev mode, or realistic production use cases like<Activity />).The problem is that now, on the first mount, we are always running styles and rules updates twice.
Fix
This PR makes one overarching change comprised of two back-to-back changes (and adds some regression tests) to resolve this:
useEffectis mounted, resubscribe to the last known calculated rules (i.e. from the state initializer) IFF they are available / without runningupdateRules.styleEffectorruleEffect's change (i.e. while the components or effects are mounted... see next bullet).<Activity mode="hidden" />-- also recalculate the rules.The benchmark now runs better, in line with the library prior to the Expo 57 fixes.