Skip to content

Use MutableIntObjectMap for SurfaceMountingManager view registry (#56646)#56646

Closed
javache wants to merge 1 commit intofacebook:mainfrom
javache:export-D102797904
Closed

Use MutableIntObjectMap for SurfaceMountingManager view registry (#56646)#56646
javache wants to merge 1 commit intofacebook:mainfrom
javache:export-D102797904

Conversation

@javache
Copy link
Copy Markdown
Member

@javache javache commented Apr 28, 2026

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

@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 28, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Apr 28, 2026

@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
@meta-codesync meta-codesync Bot changed the title Use MutableIntObjectMap for SurfaceMountingManager view registry Use MutableIntObjectMap for SurfaceMountingManager view registry (#56646) May 1, 2026
@javache javache force-pushed the export-D102797904 branch from 6deb66c to 8c309d1 Compare May 1, 2026 11:05
@meta-codesync meta-codesync Bot closed this in 06b23b8 May 1, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 1, 2026

This pull request has been merged in 06b23b8.

@facebook-github-tools facebook-github-tools Bot added the Merged This PR has been merged. label May 1, 2026
@react-native-bot
Copy link
Copy Markdown
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?

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