Skip to content

fix: 30fps layout animations on iOS release builds - #9616

Merged
bartlomiejbloniarz merged 2 commits into
mainfrom
@bartlomiejbloniarz/fix-release-30fps
Jun 9, 2026
Merged

bartlomiejbloniarz merged 2 commits into
mainfrom
@bartlomiejbloniarz/fix-release-30fps

Conversation

@bartlomiejbloniarz

Copy link
Copy Markdown
Member

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 progressLayoutAnimation scheduled the commit through requestRenderForLayoutAnimations(), which posts a render request on REANodesManager'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 worklets AnimationFrameQueue, the commit (performOperations) on REANodesManager — 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 single ReactChoreographer callback 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 all requestAnimationFrame callbacks), calling _maybeFlushUIUpdatesQueue. That's independent of display-link ordering, so the commit lands every frame. This also lets us drop requestRenderForLayoutAnimations and the gate flag entirely. The animation-backend path already drives its own flush from runGrandCallback, so it's untouched — progressLayoutAnimation / endLayoutAnimation just record the surface in layoutAnimationFlushRequests_.

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 LinearTransition layout animations). Before: the tiles step every other frame (30 FPS). After: smooth 60 FPS, matching Debug.

Example
import React, { useEffect, useRef, useState } from 'react';
import { Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';
import Animated, {
  LinearTransition,
  ZoomIn,
  ZoomOut,
} from 'react-native-reanimated';

const COLORS = [
  '#ef4444', '#f97316', '#f59e0b', '#eab308', '#84cc16', '#22c55e',
  '#10b981', '#14b8a6', '#06b6d4', '#0ea5e9', '#3b82f6', '#6366f1',
  '#8b5cf6', '#a855f7', '#d946ef', '#ec4899',
];

type Tile = { id: string; color: string };

let nextId = 0;
const makeTile = (): Tile => ({
  id: `t-${nextId++}`,
  color: COLORS[Math.floor(Math.random() * COLORS.length)],
});

const initialTiles = () => Array.from({ length: 100 }, makeTile);

export default function StressDemo() {
  const [tiles, setTiles] = useState<Tile[]>(initialTiles);
  const [spam, setSpam] = useState(false);
  const tickRef = useRef(0);

  const add = (n: number) =>
    setTiles((prev) => [...prev, ...Array.from({ length: n }, makeTile)]);
  const remove = (n: number) =>
    setTiles((prev) => prev.slice(0, Math.max(0, prev.length - n)));
  const shuffle = () =>
    setTiles((prev) => [...prev].sort(() => Math.random() - 0.5));
  const reset = () => setTiles(initialTiles());
  useEffect(() => {
    if (!spam) return;
    const id = setInterval(() => {
      const phase = tickRef.current++ % 3;
      if (phase === 0) add(20);
      else if (phase === 1) remove(20);
      else shuffle();
    }, 500);
    return () => clearInterval(id);
  }, [spam]);

  return (
    <View style={styles.container}>
      <View style={styles.toolbar}>
        <Pressable style={styles.button} onPress={() => add(20)}>
          <Text style={styles.buttonText}>+20</Text>
        </Pressable>
        <Pressable style={styles.button} onPress={() => remove(20)}>
          <Text style={styles.buttonText}>-20</Text>
        </Pressable>
        <Pressable style={styles.button} onPress={shuffle}>
          <Text style={styles.buttonText}>Shuffle</Text>
        </Pressable>
        <Pressable
          style={[styles.button, spam && styles.buttonActive]}
          onPress={() => setSpam((s) => !s)}>
          <Text style={styles.buttonText}>{spam ? 'Stop' : 'Spam'}</Text>
        </Pressable>
        <Pressable style={styles.button} onPress={reset}>
          <Text style={styles.buttonText}>Reset</Text>
        </Pressable>
      </View>

      <Text style={styles.count}>
        Tiles: {tiles.length} · ZoomIn / ZoomOut / LinearTransition
      </Text>

      <ScrollView contentContainerStyle={styles.grid}>
        {tiles.map((tile) => (
          <Animated.View
            key={tile.id}
            entering={ZoomIn.duration(250)}
            exiting={ZoomOut.duration(250)}
            layout={LinearTransition.duration(250)}
            style={[styles.tile, { backgroundColor: tile.color }]}
          />
        ))}
      </ScrollView>
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1 },
  toolbar: {
    flexDirection: 'row',
    flexWrap: 'wrap',
    padding: 8,
    gap: 8,
    backgroundColor: '#f3f4f6',
  },
  button: {
    paddingHorizontal: 12,
    paddingVertical: 8,
    backgroundColor: '#1f2937',
    borderRadius: 6,
  },
  buttonActive: { backgroundColor: '#dc2626' },
  buttonText: { color: 'white', fontWeight: '600' },
  count: {
    paddingHorizontal: 12,
    paddingVertical: 4,
    fontWeight: '600',
    color: '#374151',
  },
  grid: {
    flexDirection: 'row',
    flexWrap: 'wrap',
    padding: 8,
    gap: 6,
  },
  tile: {
    width: 50,
    height: 50,
    borderRadius: 6,
  },
});

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bartlomiejbloniarz
bartlomiejbloniarz added this pull request to the merge queue Jun 9, 2026
Merged via the queue into main with commit 9535c11 Jun 9, 2026
20 checks passed
@bartlomiejbloniarz
bartlomiejbloniarz deleted the @bartlomiejbloniarz/fix-release-30fps branch June 9, 2026 07:57
MatiPl01 added a commit that referenced this pull request Jun 22, 2026
#9616) (#9724)

## Summary

Cherry-picking for Reanimated 4.4.2 release
- #9616

Co-authored-by: Bartłomiej Błoniarz <bartlomiej.bloniarz@gmail.com>
divbzero added a commit to ChildMindInstitute/mindlogger-app-refactor that referenced this pull request Oct 6, 2026
🔗 [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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS][4.4.0] Performance degradation for layout animations on release builds

4 participants