Repository navigation
[discord] UIManagerConstantsCache - build the constants native map on first request - #53
Merged
Merged
Conversation
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.
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.
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.
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 fromMainApplication.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.)