Skip to content

Fix debug build memory leak from fabric marker in updatePropsSynchronously (#56561)#56561

Closed
zeyap wants to merge 1 commit into
react:mainfrom
zeyap:export-D101843147
Closed

Fix debug build memory leak from fabric marker in updatePropsSynchronously (#56561)#56561
zeyap wants to merge 1 commit into
react:mainfrom
zeyap:export-D101843147

Conversation

@zeyap

@zeyap zeyap commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary:

Changelog:

[Internal] [Fixed] - Fix debug build memory leak from fabric marker in updatePropsSynchronously

Problem

FabricUIManager.synchronouslyUpdateViewOnUIThread logs FABRIC_UPDATE_UI_MAIN_THREAD_START/END fabric markers with a unique, ever-incrementing commitNumber. While Fb4aReactFabricPerfLogger consumed these markers correctly (via its EventMetadata pattern), DevToolsReactPerfLogger stored them in its fabricCommitMarkers map and only cleaned up entries on FABRIC_BATCH_EXECUTION_END — which is never emitted for synchronous updates. At 60fps with multiple animated views, ~300 orphaned FabricCommitPoint entries accumulated per second, causing unbounded memory growth.

Why only UPDATE_UI_MAIN_THREAD is affected

All other fabric markers (COMMIT, DIFF, LAYOUT, FINISH_TRANSACTION, BATCH_EXECUTION) are emitted from the normal commit lifecycle in C++ → IntBufferBatchMountItem. They share the same commitNumber and always terminate with BATCH_EXECUTION_END, so they get cleaned up. UPDATE_UI_MAIN_THREAD is the only marker emitted from a separate path (synchronouslyUpdateViewOnUIThread) with its own commitNumber space (starting at 10000) and no BATCH_EXECUTION_END.

Fix

DevToolsReactPerfLogger now also treats FABRIC_UPDATE_UI_MAIN_THREAD_END as a commit-end signal, triggering onFabricCommitEnd and cleanup of the fabricCommitMarkers entry. This is safe because UPDATE_UI_MAIN_THREAD markers are only emitted by synchronouslyUpdateViewOnUIThread (which never emits BATCH_EXECUTION_END), while normal commits use BATCH_EXECUTION_END (and never emit UPDATE_UI_MAIN_THREAD). No double-cleanup risk.

Reviewed By: cipolleschi

Differential Revision: D101843147

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 22, 2026
@meta-codesync

meta-codesync Bot commented Apr 22, 2026

Copy link
Copy Markdown

@zeyap has exported this pull request. If you are a Meta employee, you can view the originating Diff in D101843147.

…ously (react#56561)

Summary:

## Changelog:

[Internal] [Fixed] - Fix debug build memory leak from fabric marker in updatePropsSynchronously

## Problem

`FabricUIManager.synchronouslyUpdateViewOnUIThread` logs `FABRIC_UPDATE_UI_MAIN_THREAD_START/END` fabric markers with a unique, ever-incrementing `commitNumber`. While `Fb4aReactFabricPerfLogger` consumed these markers correctly (via its `EventMetadata` pattern), `DevToolsReactPerfLogger` stored them in its `fabricCommitMarkers` map and only cleaned up entries on `FABRIC_BATCH_EXECUTION_END` — which is never emitted for synchronous updates. At 60fps with multiple animated views, ~300 orphaned `FabricCommitPoint` entries accumulated per second, causing unbounded memory growth.

## Why only UPDATE_UI_MAIN_THREAD is affected

All other fabric markers (COMMIT, DIFF, LAYOUT, FINISH_TRANSACTION, BATCH_EXECUTION) are emitted from the normal commit lifecycle in C++ → `IntBufferBatchMountItem`. They share the same `commitNumber` and always terminate with `BATCH_EXECUTION_END`, so they get cleaned up. `UPDATE_UI_MAIN_THREAD` is the only marker emitted from a separate path (`synchronouslyUpdateViewOnUIThread`) with its own `commitNumber` space (starting at 10000) and no `BATCH_EXECUTION_END`.

## Fix

`DevToolsReactPerfLogger` now also treats `FABRIC_UPDATE_UI_MAIN_THREAD_END` as a commit-end signal, triggering `onFabricCommitEnd` and cleanup of the `fabricCommitMarkers` entry. This is safe because `UPDATE_UI_MAIN_THREAD` markers are only emitted by `synchronouslyUpdateViewOnUIThread` (which never emits `BATCH_EXECUTION_END`), while normal commits use `BATCH_EXECUTION_END` (and never emit `UPDATE_UI_MAIN_THREAD`). No double-cleanup risk.

Reviewed By: cipolleschi

Differential Revision: D101843147
@meta-codesync meta-codesync Bot changed the title Fix debug build memory leak from fabric marker in updatePropsSynchronously Fix debug build memory leak from fabric marker in updatePropsSynchronously (#56561) Apr 22, 2026
@zeyap zeyap force-pushed the export-D101843147 branch from eac0fd7 to 01c9155 Compare April 22, 2026 14:22
@meta-codesync meta-codesync Bot closed this in f437b2c Apr 22, 2026
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @zeyap in f437b2c

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Apr 22, 2026
@meta-codesync

meta-codesync Bot commented Apr 22, 2026

Copy link
Copy Markdown

This pull request has been merged in f437b2c.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants