Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[net6] Don't blindly load Mono components #6507

Merged
merged 2 commits into from Nov 19, 2021

Conversation

grendello
Copy link
Member

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.
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 xamarin: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.

None yet

3 participants