Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Jan 23, 2025

If using $(AndroidEnableAssemblyCompression) today, we do not compress assemblies incrementally. That is, we always compress every assembly even if they haven't changed since the previous build.

Update the CompressAssemblies task to check if the input is newer than the output, and skip recompressing if the input has not changed.

This is most visible with the following test case:

dotnet new android
dotnet build -p:EmbedAssembliesIntoApk=true -p:AndroidIncludeDebugSymbols=false
Scenario (CompressAssemblies tasks) main This PR
Full 44.26 s 44.2 s
NoChanges not run 34 ms
ChangeResource 27.8 s 9 ms
AddResource 25.81 s 25 ms
ChangeCSharp 25.87 s 30 ms
ChangeCSharpJLO 27.04 s 23.36 s

ChangeCSharpJLO should be similarly reduced, however something earlier in the build process is causing Mono.Android.dll to get touched so it is getting recompressed. We'll leave that as an investigation for another day.

@jpobst jpobst force-pushed the dev/jpobst/incremental-compression branch from d217bf1 to 679a43e Compare January 27, 2025 22:48
@jpobst jpobst force-pushed the dev/jpobst/incremental-compression branch from 679a43e to c097ec2 Compare January 28, 2025 18:01
@jpobst jpobst marked this pull request as ready for review January 28, 2025 22:50
@jpobst jpobst requested a review from grendello as a code owner January 28, 2025 22:50
case CompressionResult.EncodingFailed:
log.LogMessage ($"Failed to compress {sourceAssembly}");
break;
case CompressionResult.InputTooBig:
Copy link
Contributor

Choose a reason for hiding this comment

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

Reviewing the full code file this does not seem to be enabled anymore? The code which raised this issue is commented out.

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 don't know why that error condition is disabled in the existing code, but I think it's fine to ensure we log it properly if it ever gets reenabled.

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.

Could this test be updated:

Assert.IsTrue (b.Build (proj), "third build failed");
Assert.IsFalse (
b.Output.IsTargetSkipped ("_Sign"),
"the _Sign target should run");

To check:

b.Output.AssertTargetIsPartiallyBuilt ("_CompressAssemblies"); 

-->
<Target Name="_CompressAssemblies"
DependsOnTargets="_CollectAssembliesToCompress"
Inputs="@(_AssembliesToCompress);@(_AndroidMSBuildAllProjects)"
Copy link
Member

Choose a reason for hiding this comment

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

You might also add:

Suggested change
Inputs="@(_AssembliesToCompress);@(_AndroidMSBuildAllProjects)"
Inputs="@(_AssembliesToCompress);@(_AndroidMSBuildAllProjects);$(_AndroidBuildPropertiesCache)"

The build.props file has been the thing used to rerun all targets no matter what.

@jpobst
Copy link
Contributor Author

jpobst commented Feb 4, 2025

Updated with feedback, I think this is ready.

@jpobst jpobst merged commit 44c5c30 into main Feb 4, 2025
58 checks passed
@jpobst jpobst deleted the dev/jpobst/incremental-compression branch February 4, 2025 21:01
grendello added a commit that referenced this pull request Feb 5, 2025
* main:
  [XABT] Make assembly compression incremental. (#9704)
@github-actions github-actions bot locked and limited conversation to collaborators Mar 7, 2025
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.

5 participants