Use MutableIntObjectMap for SurfaceMountingManager view registry (#56646)#56646
Closed
javache wants to merge 1 commit intofacebook:mainfrom
Closed
Use MutableIntObjectMap for SurfaceMountingManager view registry (#56646)#56646javache wants to merge 1 commit intofacebook:mainfrom
javache wants to merge 1 commit intofacebook:mainfrom
Conversation
|
@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D102797904. |
…ebook#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 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