Fix debug build memory leak from fabric marker in updatePropsSynchronously (#56561)#56561
Closed
zeyap wants to merge 1 commit into
Closed
Fix debug build memory leak from fabric marker in updatePropsSynchronously (#56561)#56561zeyap wants to merge 1 commit into
zeyap wants to merge 1 commit into
Conversation
|
@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
eac0fd7 to
01c9155
Compare
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? |
|
This pull request has been merged in f437b2c. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Changelog:
[Internal] [Fixed] - Fix debug build memory leak from fabric marker in updatePropsSynchronously
Problem
FabricUIManager.synchronouslyUpdateViewOnUIThreadlogsFABRIC_UPDATE_UI_MAIN_THREAD_START/ENDfabric markers with a unique, ever-incrementingcommitNumber. WhileFb4aReactFabricPerfLoggerconsumed these markers correctly (via itsEventMetadatapattern),DevToolsReactPerfLoggerstored them in itsfabricCommitMarkersmap and only cleaned up entries onFABRIC_BATCH_EXECUTION_END— which is never emitted for synchronous updates. At 60fps with multiple animated views, ~300 orphanedFabricCommitPointentries 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 samecommitNumberand always terminate withBATCH_EXECUTION_END, so they get cleaned up.UPDATE_UI_MAIN_THREADis the only marker emitted from a separate path (synchronouslyUpdateViewOnUIThread) with its owncommitNumberspace (starting at 10000) and noBATCH_EXECUTION_END.Fix
DevToolsReactPerfLoggernow also treatsFABRIC_UPDATE_UI_MAIN_THREAD_ENDas a commit-end signal, triggeringonFabricCommitEndand cleanup of thefabricCommitMarkersentry. This is safe becauseUPDATE_UI_MAIN_THREADmarkers are only emitted bysynchronouslyUpdateViewOnUIThread(which never emitsBATCH_EXECUTION_END), while normal commits useBATCH_EXECUTION_END(and never emitUPDATE_UI_MAIN_THREAD). No double-cleanup risk.Reviewed By: cipolleschi
Differential Revision: D101843147