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

[Mono] Optimize mono_dl_build_path for component and Android module loading. #54971

Merged

Conversation

lateralusX
Copy link
Member

@lateralusX lateralusX commented Jun 30, 2021

mono_dl_build_path probes a lot of variations of paths and in some situations where modules uses platform specific naming, it could try at least two paths before getting to the correct one. This have been a problem for Android a long time since IO is slow
on devices, so always failing two probes per module load adds to the startup time on Android.

For dynamic component loading the existing schema is particular bad since the scenario of disabling a component means that the component won't exist, and using the existing probing it could do 3 or more load attempts before realize that the component is not present and use the stub implmenentation.

Commit splits current mono_dl_build_path probing logic so it can be customized.

For components a new function has been added that will always use platform prefix and platform suffixes, and if not found
it will stop looking. For most platform that means only one attempt to load a component instead of at least 3, optimize both the scenario when the component is awailable as well as when it should be disabled.

Commit also change the default behavior of mono_dl_build_path on Android reversing current schema making it more likely to find modules using platform specific naming, like lib*.so, in first attempt. It will still fallback using no prefix and default suffix and then the verbatim name to make sure dllimports will still work as before, but favorizing modules using platform specific naming.

On all other platforms mono_dl_build_path will continue to keep its current behaviour.

@ghost
Copy link

ghost commented Jun 30, 2021

Tagging subscribers to this area:
See info in area-owners.md if you want to be subscribed.

Issue Details

mono_dl_build_path probes a lot of variations of paths and in some situations where modules uses platform specific naming, it could try at least two paths before getting to the correct one. This have been a problem for Android a long time since IO is slow
on devices, so always failing two probes per module load adds to the startup time on Android.

For dynamic component loading the existing schema is particular bad since the scenario of disabling a component means that the component won't exist, and using the existing probing it could do 3 or more load attempts before realize that the component is not present and use the stub implmenentation.

Commit splits current mono_dl_build_path probing logic so it can be customized.

For components a new function has been added that will always use platform prefix and platform suffixes, and if not found
it will stop looking. For most platform that means only one attempt to load a component instead of at least 3, optimize both the scenario when the component is awailable as well as when it should be disabled.

Commit also change the default behavior of mono_dl_build_path on Android reversing current schema making it more likely to find modules using platform specific naming, like libMyLibrary.so, in first attempt. It will still fallback using no prefix and default suffix and then the verbatim name to make sure dllimports will still work as before, but favorizing modules using platform specific naming.

On all other platforms mono_dl_build_path will continue to keep its current behaviour.

Author: lateralusX
Assignees: -
Labels:

area-VM-meta-mono

Milestone: -

@lateralusX
Copy link
Member Author

//cc @grendello

@lateralusX lateralusX force-pushed the lateralusX/optimize-component-loading branch 2 times, most recently from a35c8db to 56156d0 Compare July 1, 2021 11:44
mono_dl_build_path probes a lot of variations of paths and in some
situations where modules uses platform specific naming,
it could try at least two paths before getting to the correct one.
This have been a problem for Android a long time since IO is slow
on devices, so always failing two probes per module load adds to
the startup time on Android.

For dynamic component loading the existing schema is particular
bad since the scenario of disabling a component means that the component
won't exist, and using the existing probing it could do 3 or more
load attempts before realize that the component is not present and
use the stub implmenentation.

Commit splits current mono_dl_build_path probing logic so it can be
customized.

For components a new function has been added that will
always use platform prefix and platform suffixes, and if not found
it will stop looking. For most platform that means only one attempt
to load a component instead of at least 3, optimize both the scenario
when the component is awailable as well as when it should be disabled.

Commit also change the default behavior of mono_dl_build_path on Android
reversing current schema making it more likely to find modules using
platform specific naming, like libMyLibrary.so, in first attempt.
It will still fallback using no prefix and default suffix and then
the verbatim name to make sure dllimports will still work as before, but
favorizing modules using platform specific naming.

On all other platforms mono_dl_build_path will continue to keep
its current behaviour.
Cache try load history reduce try_load calls when library host
multiple components (like diagnostics_tracing).

Change mobile to not try components_dir, just loading using name directly.

Above changes result in mono_dl_get_so_suffixes number of
dl_open attempts per component library and on Android that will be
one attempt independt of components begin enabled or disabled.
@lateralusX lateralusX force-pushed the lateralusX/optimize-component-loading branch from 56156d0 to 032341f Compare July 4, 2021 11:52
@lateralusX
Copy link
Member Author

@lambdageek Still ok after adjustments?

@lateralusX lateralusX merged commit c865a54 into dotnet:main Jul 6, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants