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

[Xamarin.Android.Build.Tasks] cache java -version output #1938

Merged
merged 1 commit into from
Jul 15, 2018

Conversation

jonathanpeppers
Copy link
Member

Context: https://github.com/Microsoft/msbuild/blob/f147a76a60bf9e516800f65f9614c914df0a4f15/src/Framework/IBuildEngine4.cs#L34-L84
Context: https://github.com/xamarin/Xamarin.Forms/blob/42c07d1ae5aa56eb574b7d169499f1a9af7ec080/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj

The new ValidateJavaVersion MSBuild task gets invoked for every
project on every build, regardless if there are changes or not.
Unfortunately, this task also takes around 250ms to run, since it
shells out to java -version and javac -version.

We can use MSBuild's GetRegisteredTaskObject and
RegisterTaskObject to cache the output of running these command line
tools. If we key with the full path to java or javac, the cache
should be properly invalidated if a different JavaSdkPath is passed
in. I added a new set of ValidateJavaVersionTests to directly test
this caching functionality, plus a couple smoke tests.

In the case of Xamarin.Forms.ControlGallery.Android:

  • ValidateJavaVersion runs 7 times
  • A build (with no changes) went from 12.820s to 11.185s, saving
    ~1.635s of build time
  • I also tested the changes in VS Windows, and was able to see logs
    indicating the value is cached.

Improvements to MockBuildEngine:

  • General code formatting / refactoring
  • Added a Messages list that can be asserted against
  • Refactored the Task APIs so that they are fully functional

Other changes:

  • Since BaseTest now has a SetUp class, we can't have a method
    named SetUp or we get a warning. I used a Setup method (with
    lowercase u) instead, and modified KeyToolTests to fix this
    warning.

Context: https://github.com/Microsoft/msbuild/blob/f147a76a60bf9e516800f65f9614c914df0a4f15/src/Framework/IBuildEngine4.cs#L34-L84
Context: https://github.com/xamarin/Xamarin.Forms/blob/42c07d1ae5aa56eb574b7d169499f1a9af7ec080/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj

The new `ValidateJavaVersion` MSBuild task gets invoked for *every*
project on *every* build, regardless if there are changes or not.
Unfortunately, this task also takes around 250ms to run, since it
shells out to `java -version` and `javac -version`.

We can use MSBuild's `GetRegisteredTaskObject` and
`RegisterTaskObject` to cache the output of running these command line
tools. If we key with the full path to `java` or `javac`, the cache
should be properly invalidated if a different `JavaSdkPath` is passed
in. I added a new set of `ValidateJavaVersionTests` to directly test
this caching functionality, plus a couple smoke tests.

In the case of `Xamarin.Forms.ControlGallery.Android`:
- `ValidateJavaVersion` runs 7 times
- A build (with no changes) went from 12.820s to 11.185s, saving
  ~1.635s of build time
- I also tested the changes in VS Windows, and was able to see logs
  indicating the value is cached.

Improvements to `MockBuildEngine`:
- General code formatting / refactoring
- Added a `Messages` list that can be asserted against
- Refactored the `Task` APIs so that they are fully functional

Other changes:
- Since `BaseTest` now has a `SetUp` class, we can't have a method
  named `SetUp` or we get a warning. I used a `Setup` method (with
  lowercase u) instead, and modified `KeyToolTests` to fix this
  warning.
@jonathanpeppers jonathanpeppers added the do-not-merge PR should not be merged. label Jul 9, 2018
@jonathanpeppers
Copy link
Member Author

Let's wait and make sure #1916 is good (bumped in monodroid) before we merge this one.

@jonathanpeppers jonathanpeppers removed the do-not-merge PR should not be merged. label Jul 12, 2018
@jonathanpeppers
Copy link
Member Author

#1916 is now in monodroid/master, things seem to be OK.

@jonpryor jonpryor merged commit 4a5dd01 into dotnet:master Jul 15, 2018
jonpryor pushed a commit that referenced this pull request Aug 3, 2018
Context: https://github.com/Microsoft/msbuild/blob/f147a76a60bf9e516800f65f9614c914df0a4f15/src/Framework/IBuildEngine4.cs#L34-L84
Context: https://github.com/xamarin/Xamarin.Forms/blob/42c07d1ae5aa56eb574b7d169499f1a9af7ec080/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj

The new `<ValidateJavaVersion/>` MSBuild task (93ddf96) gets invoked
for *every* project on *every* build, even if nothing changed.
Unfortunately, this task also takes around 250ms to run, since it
shells out to `java -version` and `javac -version`.

We can use MSBuild's `GetRegisteredTaskObject()` and
`RegisterTaskObject()` to cache the output of running these command
line tools.  If we key with the full path to `java` or `javac`, the
cache should be properly invalidated if a different
`$(JavaSdkDirectory)` value is passed in.  I added a new set of
`ValidateJavaVersionTests` to directly test this caching
functionality, plus a couple smoke tests.

In the case of `Xamarin.Forms.ControlGallery.Android`:

  - `<ValidateJavaVersion/>` runs 7 times
  - A build (with no changes) went from 12.820s to 11.185s, saving
    ~1.635s of build time
  - I also tested the changes in VS Windows, and was able to see logs
    indicating the value is cached.

Improvements to `MockBuildEngine`:

  - General code formatting / refactoring
  - Added a `Messages` list that can be asserted against
  - Refactored the `Task` APIs so that they are fully functional

Other changes:

  - Since `BaseTest` now has a `SetUp` class, we can't have a method
    named `SetUp` or we get a warning. I used a `Setup` method (with
    lowercase u) instead, and modified `KeyToolTests` to fix this
    warning.
@jonathanpeppers jonathanpeppers deleted the java-javac-caching branch November 2, 2018 20:36
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 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