[net6] Don't blindly load Mono components #6507
Merged
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.
Whenever a NET6 Xamarin.Android app starts, MonoVM will probe for a
number of Mono components:
The above is repeated for, currently, 3 components. Together, the
failed load attempts cost us around 1ms of startup time (on Pixel 3 XL,
the amount of time will depend on the speed of device's storage and CPU)
Since we know at the build time which components are included, we can
optimize the startup process by recording a flag indicating which
components can be loaded successfully.
Add a
mono_components_mask
field toApplicationConfig
which is setto a bitmask indicating which components are packaged. On application
startup, whenever
monodroid_dlopen
is called, we has the name of thelibrary passed to us by Mono and see if it matches one of the known
hashes for the various components. If yes, we consult the mask stored
at build time and attempt to load the component only if its bit is set.
The above check is performed only during application startup since
that's when Mono probes for the components and it would be a waste of
time later in the application life.