Skip to content

Conversation

@grendello
Copy link
Contributor

Whenever a NET6 Xamarin.Android app starts, MonoVM will probe for a
number of Mono components:

11-16 14:23:24.805 10791 10791 I monodroid-assembly: Trying to load shared library '/data/app/~~5lwn5C40pkRva2-L4kilZA==/com.microsoft.net6.helloandroid-MrYUTOqX7yZPkmtLOPnuuw==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libmono-component-debugger.so'
11-16 14:23:24.806 10791 10791 I monodroid-assembly: Failed to load shared library '/data/app/~~5lwn5C40pkRva2-L4kilZA==/com.microsoft.net6.helloandroid-MrYUTOqX7yZPkmtLOPnuuw==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libmono-component-debugger.so'.
                                                     dlopen failed: library "/data/app/~~5lwn5C40pkRva2-L4kilZA==/com.microsoft.net6.helloandroid-MrYUTOqX7yZPkmtLOPnuuw==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libmono-component-debugger.so" not found

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 to ApplicationConfig which is set
to a bitmask indicating which components are packaged. On application
startup, whenever monodroid_dlopen is called, we has the name of the
library 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.

Whenever a NET6 Xamarin.Android app starts, MonoVM will probe for a
number of Mono components:

    11-16 14:23:24.805 10791 10791 I monodroid-assembly: Trying to load shared library '/data/app/~~5lwn5C40pkRva2-L4kilZA==/com.microsoft.net6.helloandroid-MrYUTOqX7yZPkmtLOPnuuw==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libmono-component-debugger.so'
    11-16 14:23:24.806 10791 10791 I monodroid-assembly: Failed to load shared library '/data/app/~~5lwn5C40pkRva2-L4kilZA==/com.microsoft.net6.helloandroid-MrYUTOqX7yZPkmtLOPnuuw==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libmono-component-debugger.so'.
                                                         dlopen failed: library "/data/app/~~5lwn5C40pkRva2-L4kilZA==/com.microsoft.net6.helloandroid-MrYUTOqX7yZPkmtLOPnuuw==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libmono-component-debugger.so" not found

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 to `ApplicationConfig` which is set
to a bitmask indicating which components are packaged.  On application
startup, whenever `monodroid_dlopen` is called, we has the name of the
library 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.
@grendello grendello force-pushed the dont-load-missing-components branch from bfd59ca to 0f5ebea Compare November 18, 2021 21:30
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSBuild changes LGTM 👍

@jonpryor jonpryor merged commit 000cf5a into dotnet:main Nov 19, 2021
@grendello grendello deleted the dont-load-missing-components branch November 19, 2021 16:04
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants