Repository navigation
fix: 30fps layout animations on iOS release builds - #9616
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an iOS Release-build regression where layout animations (entering / exiting / layout) effectively ran at ~30 FPS due to nondeterministic ordering between two independent CADisplayLink sources (worklets progress vs. REANodesManager commits). It changes the non-animation-backend path to flush layout-animation progress once per frame via the UI runtime’s requestAnimationFrameFinalizer, aligning it with the existing animated-props flushing mechanism and removing the previous cross-display-link render-request gate.
Changes:
- Schedule a per-frame (deduped) flush for layout-animation progress/end notifications on the non-backend path via
requestAnimationFrameFinalizer→global._maybeFlushUIUpdatesQueue(). - Remove
requestRenderForLayoutAnimations()and its in-flight gate (layoutAnimationRenderRequested_) from the native proxy, relying on the new flush mechanism / backend-driven flushing. - Ensure layout-animation progress/end only records surfaces to flush (
layoutAnimationFlushRequests_), which is drained during normal flush/commit execution.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react-native-reanimated/src/layoutReanimation/animationsManager.ts | Adds a deduped per-frame flush scheduled from UI runtime finalizers for non-backend layout-animation progress/end. |
| packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h | Removes the layout-animation render-request helper and its boolean gate member. |
| packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp | Stops scheduling render requests from progress/end callbacks; only records flush requests and updates comments accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🔗 [Jira Ticket M2-11131](https://mindlogger.atlassian.net/browse/M2-11131) We updated `react-native-reanimated` from `3.19.5` to `4.4.1` in commit 173b5e6 of #1155 but `react-native-reanimated@4.4.1` contains an iOS FPS regression reported in issue software-mansion/react-native-reanimated#9591. The iOS FPS regression was fixed in pull request software-mansion/react-native-reanimated#9616 and released with [`4.4.2`](https://github.com/software-mansion/react-native-reanimated/releases/tag/4.4.2). Changes include: - Update `react-native-reanimated` from `4.4.1` to `4.4.3` to include fix in `4.4.2`. `4.4.3` is the latest `4.4.x` version of `react-native-reanimated`. Updating `react-native-reanimated` to `4.5.x` or beyond would require updating `react-native-worklets` to `0.10.x` which could reintroduce an app crash on Unity exit that @adeiji fixed in commit c809a8a. Merged as part of stack ending with #1203. CI skipped until last pull request is merged. [skip ci]
Summary
Fixes #9591.
Layout animations (
entering/exiting/layout) run at 30 FPS on iOS Release builds while staying smooth at 60 FPS in Debug. This is a regression from #9431.On the non-backend path, every
progressLayoutAnimationscheduled the commit throughrequestRenderForLayoutAnimations(), which posts a render request onREANodesManager's display link, deduped by a single-in-flight flag (layoutAnimationRenderRequested_) that the commit clears.The catch is that progress and the commit run on two independent
CADisplayLinks — progress on the workletsAnimationFrameQueue, the commit (performOperations) onREANodesManager— and the two links are registered at different times, so their firing order within a frame isn't pinned. When the progress link fires first, it checks the flag before the commit has cleared it that frame, the render request is dropped, and the commit only runs every other frame → 30 FPS. Release happens to settle on progress-before-commit; Debug gets the opposite order and stays at 60 FPS. Android isn't affected because both frame sources go through a singleReactChoreographercallback queue.Instead of that gated cross-display-link request, we now flush layout-animation progress the same way animated-prop updates already do: once per frame from the worklet runtime's
requestAnimationFrameFinalizer(which runs after allrequestAnimationFramecallbacks), calling_maybeFlushUIUpdatesQueue. That's independent of display-link ordering, so the commit lands every frame. This also lets us droprequestRenderForLayoutAnimationsand the gate flag entirely. The animation-backend path already drives its own flush fromrunGrandCallback, so it's untouched —progressLayoutAnimation/endLayoutAnimationjust record the surface inlayoutAnimationFlushRequests_.Test plan
Run the example below on iOS in Release and hold the Spam button (it adds / removes / shuffles tiles on an interval, driving continuous
LinearTransitionlayout animations). Before: the tiles step every other frame (30 FPS). After: smooth 60 FPS, matching Debug.Example