Skip to content

[iOS][Fabric] ScrollView walks its whole subtree (convertRect per view) after every mounting transaction, even with no removeClippedSubviews; multi-second hangs on iPad #60227

Open

Description

@beqramo

Description

On iOS with the New Architecture, every mounted ScrollView walks its entire native subtree after every mounting transaction on the surface, even when no view in that subtree sets removeClippedSubviews. Each level of the walk does a -[UIView convertRect:toView:]. With a large tree under a ScrollView (iPad layouts, long lists of cards) this costs seconds of main-thread time; when commits come every frame (Reanimated UI-thread commits, or back-to-back React commits) it runs every frame.

Code path (0.88.0, unchanged on main):

  • RCTScrollViewComponentView.mm – mountingTransactionDidMount:withSurfaceTelemetry: calls [self _remountChildren] unconditionally (0.88.0 line ~292).
  • _remountChildren (0.88.0 line ~1005) calls [_scrollView updateClippedSubviewsWithClipRect:… relativeToView:_scrollView]; it is only skipped when the enableViewCulling feature flag is on (default false).
  • RCTViewComponentView.mm updateClippedSubviewsWithClipRect:relativeToView: (~299–304): when _removeClippedSubviews is NO it falls through to super.
  • UIView+ComponentViewProtocol.mm (~164–174): the default implementation does clipRect = [clipView convertRect:clipRect toView:self] and recurses into every subview "in case any of those do support it".

So in an app that never uses removeClippedSubviews, every commit pays a full convertRect traversal of every ScrollView's content, and the walk can never clip anything.

Suggested fix: skip the walk when nothing below can use it. For example, track whether any descendant has removeClippedSubviews (a count maintained in RCTViewComponentView when the prop changes / the view mounts and unmounts) and return early from _remountChildren when it is zero; or only recurse into subviews that are, or contain, a clipping view. Running _remountChildren from mountingTransactionDidMount only when the transaction contains mutations under this ScrollView would also cut most of the cost.

Steps to reproduce

  1. iOS, New Architecture, release build.
  2. Render a ScrollView with a deep/wide subtree (a few thousand plain Views), without removeClippedSubviews.
  3. Elsewhere on the same surface, commit an update every frame (e.g. a Reanimated useAnimatedStyle driving opacity, which commits through ShadowTree::commit on the UI thread, or a JS setState in requestAnimationFrame).
  4. Profile the main thread with Instruments (Time Profiler): -[UIView(ComponentViewProtocol) updateClippedSubviewsWithClipRect:relativeToView:] and -[CALayer convertRect:toLayer:] dominate, called from -[RCTScrollViewComponentView mountingTransactionDidMount:withSurfaceTelemetry:], although nothing is clipped.
import { useEffect } from 'react';
import { ScrollView, View } from 'react-native';
import Animated, { useAnimatedStyle, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';

function Nested({ depth }: { depth: number }) {
  if (depth === 0) return <View style={{ height: 4, backgroundColor: '#ccc', margin: 1 }} />;
  return (
    <View style={{ padding: 1 }}>
      <Nested depth={depth - 1} />
      <Nested depth={depth - 1} />
    </View>
  );
}

export default function App() {
  const o = useSharedValue(1);
  useEffect(() => { o.value = withRepeat(withTiming(0, { duration: 500 }), -1, true); }, []);
  const style = useAnimatedStyle(() => ({ opacity: o.value }));
  return (
    <View style={{ flex: 1 }}>
      <Animated.View style={[{ height: 40, backgroundColor: 'tomato' }, style]} />
      <ScrollView>
        <Nested depth={11} />{/* ~4k views */}
      </ScrollView>
    </View>
  );
}

React Native Version

0.88.0 (also seen on 0.86.2; the code is unchanged on main)

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info

react-native: 0.88.0 (prebuilt React core, New Architecture)
expo: 58.0.14
react-native-reanimated: 4.7.1 (react-native-worklets)
Hermes
iOS / iPadOS: 16.7 – 27.0.1 on device (see below)
Built with Xcode / iPhoneOS 27.1 SDK on EAS

Stacktrace or Logs

Two production groups in our app, same leaf.

(a) Main-thread App Hang, 5–6 s, fully blocked (React commits from JS; 267 events / 188 users since May 2026, still occurring):

-[RCTMountingManager initiateTransaction:]
-[RCTMountingManager performTransaction:]
facebook::react::TelemetryController::pullTransaction
RCTMountingTransactionObserverCoordinator::notifyObserversMountingTransactionDidMount
-[RCTScrollViewComponentView mountingTransactionDidMount:withSurfaceTelemetry:]
-[UIView(ComponentViewProtocol) updateClippedSubviewsWithClipRect:relativeToView:]
-[UIView(ComponentViewProtocol) updateClippedSubviewsWithClipRect:relativeToView:]
-[RCTViewComponentView updateClippedSubviewsWithClipRect:relativeToView:]
-[UIView(ComponentViewProtocol) updateClippedSubviewsWithClipRect:relativeToView:]
-[RCTViewComponentView updateClippedSubviewsWithClipRect:relativeToView:]
... (alternating, ~10 levels)
-[UIView(ComponentViewProtocol) updateClippedSubviewsWithClipRect:relativeToView:]
-[UIView(Geometry) convertRect:toView:]
-[CALayer convertRect:toLayer:]
CA::Layer::map_geometry

(b) MetricKit CPU exception ("totalCPUTime: 90 sec, totalSampledTime: 175 sec"), driven every frame by Reanimated (202 events / 170 users since Oct 2026):

CA::Display::DisplayLink::dispatch_items
-[AnimationFrameQueue executeQueue:]                       (react-native-worklets)
worklets::AnimationFrameBatchinator::flush
... worklet runtime / Hermes ...
-[REANodesManager performOperations]
reanimated::ReanimatedModuleProxy::performOperations
reanimated::ReanimatedModuleProxy::commitUpdates
facebook::react::ShadowTree::commit
facebook::react::ShadowTree::tryCommit
facebook::react::ShadowTree::mount
facebook::react::UIManager::shadowTreeDidFinishTransaction
facebook::react::Scheduler::uiManagerDidFinishTransaction
-[RCTSurfacePresenter schedulerShouldRenderTransactions:]
-[RCTMountingManager performTransaction:]
RCTMountingTransactionObserverCoordinator::notifyObserversMountingTransactionDidMount
-[RCTScrollViewComponentView mountingTransactionDidMount:withSurfaceTelemetry:]
-[UIView(ComponentViewProtocol) updateClippedSubviewsWithClipRect:relativeToView:]
-[RCTViewComponentView updateClippedSubviewsWithClipRect:relativeToView:]
... (alternating)
-[UIView(Geometry) convertRect:toView:]
-[CALayer convertRect:toLayer:]
CA::Layer::map_geometry
CA::Mat4Impl::mat4_unapply_inverse_to_point2

Devices: mostly iPads. (a) iPad13,18 40, iPad12,1 31, iPad15,7 23, iPhone14,5 19, iPad13,16 12; iOS 27.0.1, 26.5–26.6.2, 18.x, 17.7.11, 16.7.16. (b) is concentrated on 2-core iPads: iPad7,11 72, iPad7,5 48, then iPad7,3/7,4/7,6/7,12, iPad11,6.

Our app sets removeClippedSubviews nowhere, so every one of these walks is a no-op apart from its cost; the alternating RCTViewComponentView / UIView(ComponentViewProtocol) frames are the pass-through path described above.

MANDATORY Reproducer

Inline snippet above (no public repo yet). The data comes from production hang/CPU telemetry in our production app; the code path is visible directly in the files referenced above.

Screenshots and Videos

No response

Activity

  1. added
    Needs: Repro
    on Nov 23, 2026
  2. react-native-bot commented on Nov 23, 2026

    @react-native-bot
    Collaborator

    Warning

    Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:


    You can read more about about it on our website: How to report a bug.

  3. beqramo commented on Nov 23, 2026

    @beqramo
    Author

    Reproducer, as requested by the bot, plus a proposed fix:

    Measured on RN 0.88.1 built from source (Release, iOS 26.5 simulator), same tree with a Reanimated opacity animation, sample for 10 s: main-thread samples in -[RCTMountingManager performTransaction:] went from 908 (809 of them in the clipping walk) to 50; app CPU from 13.8 % to 2.9 %. Clipping still detaches/reattaches rows correctly when a removeClippedSubviews ScrollView is mounted. Details in the PRs.

  4. added
    Needs: Attention
    and removed on Nov 23, 2026
  5. beqramo commented on Nov 23, 2026

    @beqramo
    Author

    Production data confirming the Reanimated path described above. Environment: RN 0.88.0 (Fabric, Hermes), Reanimated 4.7.1, worklets 0.13.0, no removeClippedSubviews.

    Sentry recorded 98 "App Hang" events of 2.1–2.9 s each in the last month, from 49 users. 86 of them come from the iPad app running on Apple-silicon Macs (Mac Catalyst). The other 12 come from iPads and iPhones on iOS 17.5 through 27.0. On the main thread, the walk runs inside a Reanimated UI-thread commit started by a display-link frame. No React commit is involved:

    CA::Display::DisplayLinkItem::dispatch_
    -[AnimationFrameQueue executeQueue:]                    AnimationFrameQueue.mm:107
    worklets::AnimationFrameBatchinator::flush              AnimationFrameBatchinator.cpp:48
    worklets::WorkletRuntime::runSync … (Hermes) …
    -[REANodesManager performOperations]                     REANodesManager.mm:128
    reanimated::ReanimatedModuleProxy::performOperations     ReanimatedModuleProxy.cpp:867
    reanimated::ReanimatedModuleProxy::commitUpdates         ReanimatedModuleProxy.cpp:1119
    facebook::react::ShadowTree::commit → tryCommit → mount
    facebook::react::UIManager::shadowTreeDidFinishTransaction
    -[RCTMountingManager performTransaction:]
    RCTMountingTransactionObserverCoordinator::notifyObserversMountingTransactionDidMount
    -[RCTScrollViewComponentView mountingTransactionDidMount:withSurfaceTelemetry:]
    -[UIView(ComponentViewProtocol) updateClippedSubviewsWithClipRect:relativeToView:]   ×~25 levels
    -[UIView(Geometry) convertRect:toView:]
    -[CALayer convertRect:toLayer:] → CA::Layer::map_geometry → ancestorSharedWithLayer:
    

    So every Reanimated frame that commits pays the whole-subtree convertRect walk synchronously, inside the display-link callback. In the latest Mac event, the frame arrived inside AppKit's NSCorrectionPanel nested event loop, triggered by the autocorrect panel while typing. The animation keeps committing during that loop. The early return in #60230 would remove this whole path for apps without clipping views.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionNeeds: Repro

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions