Repository navigation
Conversation
Apps that use SoMerging through an ExternalSoMapping (React Native in OSS) can only call init(Context, ExternalSoMapping), which always passes flags = 0, so none of the SOLOADER_* flags are available to them. This adds an overload that takes the flags as well; the existing one delegates to it. The motivating flag is SOLOADER_ENABLE_SYSTEMLOAD_WRAPPER_SOSOURCE: with it, each merged library is loaded with one System.loadLibrary call and the dynamic linker resolves its dependencies, instead of DirectApkSoSource reading the ELF DT_NEEDED entries in Java and loading each dependency through SoLoader. On a Galaxy A16 that is 20-30 ms on the main thread during Application.onCreate of a React Native app. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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
Apps that use SoMerging through an
ExternalSoMapping(React Native in OSS) can only callinit(Context, ExternalSoMapping), which always passesflags = 0, so none of theSOLOADER_*flags are available to them. Callinginit(Context, int flags)first does not work either: without the mapping,initEnableConfighonours thecom.facebook.soloader.enabled=falsemeta-data that SoLoader's own manifest contributes, SoLoader disables itself, and the merged libraries then fail to load (dlopen failed: library "libreact_featureflagsjni.so" not found).This adds
init(Context, @Nullable ExternalSoMapping, int flags);init(Context, ExternalSoMapping)delegates to it with0. The parameter order avoids an ambiguity withinit(Context, int, @Nullable SoFileLoader)for callers passingnull.Motivation
With
SOLOADER_ENABLE_SYSTEMLOAD_WRAPPER_SOSOURCE, each merged library is loaded with oneSystem.loadLibrarycall and the dynamic linker resolves itsDT_NEEDEDdependencies. TodayDirectApkSoSourcereads the dependency list in Java (SoLoader[NativeDeps]: Falling back to custom ELF parsing when loading libreactnative.so, this can be slow) and loadslibc++_shared,libjsi,libfbjni,libhermesvm, … one by one through SoLoader. In a React Native app this is 20–30 ms ofApplication.onCreateon the main thread of a Galaxy A16 (atrace:SoLoader.loadLibrary[react_featureflagsjni]20.4 ms, of which ELF parsing + the four dependency loads ≈ 15 ms;hermesinstancejni8.6 ms).React Native can get most of that today with
SoLoader.prependSoSource(new SystemLoadWrapperSoSource())afterinit(react/react-native#60066). Measured with that: RNTester release, arm64, real phones, cold starts,verifydex state, 18 interleaved launches per arm, medians with bootstrap 95 % CIs of the median difference. TTFD = time to full display (reportFullyDrawn()on the first frame with React content), TTID = time to initial display (am start -W).The prepend approach still constructs and prepares the DirectApk/Application/Backup sources it will never consult; with this overload React Native can pass the flag at init and skip them.
Test plan
./gradlew formatCheck :soloader:assembleDebugpasses.init(Context, ExternalSoMapping)→init(context, mapping, 0)is the same sequence as before (mapping set under the class lock, theninit(context, flags)).JNI_OnLoadof the merged libraries runs throughExternalSoMapping.invokeJniOnload, and theNativeDepsfallback lines disappear from logcat.🤖 Generated with Claude Code