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

Embed some data files in libxamarin-app.so #9367

Open
wants to merge 49 commits into
base: main
Choose a base branch
from

Conversation

grendello
Copy link
Contributor

@grendello grendello commented Oct 3, 2024

Runtime blob config and assembly store are two candidates for embedding now.

If these two files are embedded in libxamarin-app.so, we can skip scanning the
APK for them and, potentially, speed up startup.

Changes implemented here give us a 2% speed up on the Displayed metrics, 2.7% on
the "Native to managed" metrics and 2% on the "Total runtime init" metrics.

Tests were performed on Pixel 6 Pro, using the dotnet new android template.

@grendello grendello force-pushed the dev/grendel/embed-binaries-in-xamarinapp branch 5 times, most recently from 2730842 to 40a46b6 Compare October 10, 2024 20:28
@grendello grendello force-pushed the dev/grendel/embed-binaries-in-xamarinapp branch 4 times, most recently from 6a18219 to c69913c Compare October 16, 2024 09:22
@grendello grendello marked this pull request as ready for review October 16, 2024 15:51
@grendello grendello force-pushed the dev/grendel/embed-binaries-in-xamarinapp branch from b64f9e9 to f31d1a1 Compare October 17, 2024 18:45
@grendello grendello marked this pull request as draft October 18, 2024 11:50
@grendello grendello force-pushed the dev/grendel/embed-binaries-in-xamarinapp branch 5 times, most recently from bafa9e1 to d76969a Compare October 23, 2024 11:19
@grendello grendello force-pushed the dev/grendel/embed-binaries-in-xamarinapp branch from d76969a to c450cb6 Compare October 23, 2024 16:41
@grendello grendello marked this pull request as ready for review October 24, 2024 13:50
@grendello
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -57,6 +57,12 @@ static partial void AddManualMapping ()

public static ApplicationAttribute FromCustomAttributeProvider (ICustomAttributeProvider provider, TypeDefinitionCache cache)
{
// `provider` might be null in situations when application configuration is broken, and it surfaces in a number of
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to know more about this scenario? How is provider null when the application config is broken?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This happened in the XA0119 test (which is, itself, a broken configuration scenario) where there were no assemblies to load and the code in ManifestDocument would iterate over the list of assemblies like so:

foreach (var assemblyPath in Assemblies) {
  var assembly = Resolver.GetAssembly (assemblyPath);
  if (ApplicationAttribute.FromCustomAttributeProvider (assembly, cache) is ApplicationAttribute a) {
    assemblyAttr.Add (a);
  }
}

Each assembly is an instance of ICustomAttributeProvider, but Resolver.GetAssembly would return null since the assembly couldn't be found.

@grendello grendello force-pushed the dev/grendel/embed-binaries-in-xamarinapp branch 2 times, most recently from f2d1748 to 04b4ab8 Compare October 30, 2024 15:59
Comment on lines +581 to +585
if (assembly == null) {
log.LogDebugMessage ($"Assembly '{assemblyPath}' not found.");
continue;
}

Copy link
Member

Choose a reason for hiding this comment

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

I think you can remove this with this one merged:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'd like to keep it, it's a good safeguard for situations when something goes really wrong - at least we have a clear message in the log, instead of a NREX

override_dirs [0] = override_dir;
#if defined(DEBUG)
log_debug (LOG_DEFAULT, "Creating public update directory: `%s`", override_dir);
Util::create_public_directory (override_dir);
Copy link
Member

Choose a reason for hiding this comment

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

There are some cases we need to create the .__override__ directory in release mode that uses libmono-android.release.so:

  • Recording an AOT profile saves the custom.aprof file here
  • JIT times saves methods.txt here

These changes look like it would only create .__override__ in libmono-android.debug.so? Is that the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@grendello that link doesn't work? I think the commit was rebased

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oof, indeed, here's one which should work

if (Util::create_directory (AndroidSystem::override_dirs[0], 0777, 000) < 0) {

@grendello grendello force-pushed the dev/grendel/embed-binaries-in-xamarinapp branch from 0167776 to bc47870 Compare November 4, 2024 18:38
This reverts commit bc47870.

It broke 481 tests
@grendello
Copy link
Contributor Author

@jonathanpeppers reverting the _RemoveRegisterAttribute change broke 481 tests as the task is what actually creates the "shrunk" assemblies on disk, and those are required earlier in the process when the new CreateEmbedddedAssemblyStore target is used.

@@ -61,6 +61,10 @@ public class GeneratePackageManagerJava : AndroidTask
[Required]
public bool EnablePreloadAssembliesDefault { get; set; }

// This property should be required but it will require modifying `monodroid` first
//[Required]
public string AndroidBinUtilsDirectory { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a reference to GeneratePackageManagerJava in monodroid?

Copy link
Contributor Author

@grendello grendello Nov 5, 2024

Choose a reason for hiding this comment

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

There are none, but I got errors in some tests when the property was required. My guess is that, for some reason, AndroidBinUtilsDirectory was empty in some tests with the commercial bits present.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm interesting.

Copy link
Contributor

Choose a reason for hiding this comment

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

@grendello can we try adding the required back so I can see what the error was? It might be a build order issue which we are currently unaware of?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will push a commit in a moment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it worked this time, odd. Well, good :)

@grendello
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants