Skip to content

[discord] UIManagerConstantsCache - build the constants native map on first request - #53

Merged
joemun merged 2 commits into
0.86.0-discordfrom
joemun/constants-cache-defer-native-map
Sep 18, 2026
Merged

joemun merged 2 commits into
0.86.0-discordfrom
joemun/constants-cache-defer-native-map

Conversation

@joemun

@joemun joemun commented Sep 17, 2026 •

Copy link
Copy Markdown

Discovered this while working on an ANR (https://github.com/discord/discord/pull/318549). With that change, activity creation no longer waits for application initialization, so UIManagerConstantsCache.init() runs earlier and its loading thread starts sooner. SoLoader is initialized on its own background thread (started from MainApplication.attachBaseContext), so there is a potential race condition between SoLoader and UIManagerConstantsCache. When UIManagerConstantsCache constructs its WritableNativeMap, it calls into SoLoader, which may not have finished init yet.

Note: This change is effectively a NOOP today. The code path is currently unreachable on bridgeless, where nothing populates the cache, so cachedConstants stays null and the map is never built. (We should fix this separately. I didn't want to bundle it with this change because populating the cache could affect TTI during cold starts and app updates. Alternatively, we could just clean up this unused cache entirely.)

Constructing a WritableNativeMap loads React Native's native library through
SoLoader. The cache's loading thread starts when the host app calls init, so its
ordering against SoLoader.init is the host's to determine, not something this
class can assume. The map is therefore built in
getUIManagerConstantsAsWritableMap, once, on the first call - which comes from JS
requesting UIManager constants, after that library is loaded.
@joemun
joemun requested a review from hannojg September 17, 2026 23:50
@joemun joemun changed the title [Discord] Build the constants native map on first request [discord] UIManagerConstantsCache - build the constants native map on first request Sep 17, 2026
The JSON decoder only emits types Arguments.makeNativeMap converts, so the
guard covered nothing reachable. It also cleared the in-memory map while
leaving the MMKV blob and its version key in place, so the next start would
have read and failed on the same data.
@joemun
joemun requested a review from Flewp September 18, 2026 16:20
@joemun
joemun merged commit 4ad4507 into 0.86.0-discord Sep 18, 2026
40 checks passed
@joemun
joemun deleted the joemun/constants-cache-defer-native-map branch September 18, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant