Conversation
|
@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D102797904. |
…ct#56646) Summary: Replace `ConcurrentHashMap<Int, ViewState>` with `MutableIntObjectMap<ViewState>` + `ReentrantReadWriteLock` in `SurfaceMountingManager`, behind the `useOptimizedViewRegistryOnAndroid` feature flag. `ConcurrentHashMap<Int, ViewState>` boxes every `Int` key to `java.lang.Integer` (16 bytes) and allocates a `Node` object per entry (~32 bytes). `MutableIntObjectMap` from `androidx.collection` uses a Swiss Table layout with primitive `IntArray` keys — ~9 bytes/entry vs ~56-64 bytes, a ~6x reduction in map overhead. For a complex surface with 2000+ views, this saves ~90KB per surface in map overhead alone, plus reduced GC pressure from eliminating `Integer` boxing. The `ReentrantReadWriteLock` replaces CHM's built-in concurrency. This matches the access pattern: reads from any thread (`getEventEmitter`, `enqueuePendingEvent`), writes almost exclusively from the UI thread. Readers never block each other. `stopSurface` snapshots entries under the write lock and processes `onViewStateDeleted` outside the lock to minimize reader blocking. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D102797904
|
This pull request has been merged in 06b23b8. |
Collaborator
|
This pull request was successfully merged by @javache in 06b23b8 When will my fix make it into a release? | How to file a pick request? |
This was referenced Sep 7, 2026
meta-codesync Bot
pushed a commit
that referenced
this pull request
Sep 8, 2026
…jectMap corruption in SurfaceMountingManager (#58389) Summary: since #56646 the view registry is a `MutableIntObjectMap`; `androidx.collection` 1.4.0 to 1.4.2 corrupt `ScatterMap` and its primitive variants after remove-heavy sequences, fixed in 1.4.3 (https://issuetracker.google.com/issues/352560465). Apps resolve 1.4.0 or 1.4.2 and lose registry entries; RN then drops mount instructions and can leave stale views. Fixes #58388. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> `[ANDROID] [FIXED] - Bump androidx.collection to 1.4.4 to fix view registry entries getting lost in SurfaceMountingManager` Pull Request resolved: #58389 Test Plan: Reproducer: https://github.com/pawicao/rn-android-view-registry-corruption - RN 0.87.1 app resolving androidx.collection 1.4.2: 91 `Unable to find viewState` soft exceptions on 45 tags over two 40-round runs on a Pixel 9a, and a stale view left on screen. - Same screen with androidx.collection pinned to 1.4.4: none over 120 rounds. Reviewed By: cortinico Differential Revision: D119149754 Pulled By: javache fbshipit-source-id: afb13330bac575218a07a030bb1bcd5bf7e00824
shashikant-panchal
pushed a commit
to shashikant-panchal/react-native
that referenced
this pull request
Sep 10, 2026
…jectMap corruption in SurfaceMountingManager (react#58389) Summary: since react#56646 the view registry is a `MutableIntObjectMap`; `androidx.collection` 1.4.0 to 1.4.2 corrupt `ScatterMap` and its primitive variants after remove-heavy sequences, fixed in 1.4.3 (https://issuetracker.google.com/issues/352560465). Apps resolve 1.4.0 or 1.4.2 and lose registry entries; RN then drops mount instructions and can leave stale views. Fixes react#58388. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> `[ANDROID] [FIXED] - Bump androidx.collection to 1.4.4 to fix view registry entries getting lost in SurfaceMountingManager` Pull Request resolved: react#58389 Test Plan: Reproducer: https://github.com/pawicao/rn-android-view-registry-corruption - RN 0.87.1 app resolving androidx.collection 1.4.2: 91 `Unable to find viewState` soft exceptions on 45 tags over two 40-round runs on a Pixel 9a, and a stale view left on screen. - Same screen with androidx.collection pinned to 1.4.4: none over 120 rounds. Reviewed By: cortinico Differential Revision: D119149754 Pulled By: javache fbshipit-source-id: afb13330bac575218a07a030bb1bcd5bf7e00824
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:
Replace
ConcurrentHashMap<Int, ViewState>withMutableIntObjectMap<ViewState>+ReentrantReadWriteLockinSurfaceMountingManager, behind theuseOptimizedViewRegistryOnAndroidfeature flag.ConcurrentHashMap<Int, ViewState>boxes everyIntkey tojava.lang.Integer(16 bytes) and allocates aNodeobject per entry (~32 bytes).MutableIntObjectMapfromandroidx.collectionuses a Swiss Table layout with primitiveIntArraykeys — ~9 bytes/entry vs ~56-64 bytes, a ~6x reduction in map overhead. For a complex surface with 2000+ views, this saves ~90KB per surface in map overhead alone, plus reduced GC pressure from eliminatingIntegerboxing.The
ReentrantReadWriteLockreplaces CHM's built-in concurrency. This matches the access pattern: reads from any thread (getEventEmitter,enqueuePendingEvent), writes almost exclusively from the UI thread. Readers never block each other.stopSurfacesnapshots entries under the write lock and processesonViewStateDeletedoutside the lock to minimize reader blocking.Changelog: [Internal]
Reviewed By: sammy-SC
Differential Revision: D102797904