Skip to content

Conversation

@smocherla-brex
Copy link
Contributor

@smocherla-brex smocherla-brex commented Nov 1, 2025

By default, we create a isolated temp dir for each run of lockfile pinning for the gradle resolver for gradle.home. This means a ton of stuff is redundantly downloaded and is slow on incremental runs too without using RJE_UNSAFE_CACHE.

For the coursier resolver, we seem to be using a directory under external/ by default https://github.com/bazel-contrib/rules_jvm_external/blob/master/private/rules/coursier.bzl#L801 so incremental runs are pretty fast.

Instead we could use a directory within the runfiles of this binary so that we still keep some level of hermeticity by having this isolated but continue to leverage it on incremental runs (reuse the gradle daemon and the caches). We can chose a unique directory under /tmp that's persistent between invocations by hashing the workspace root from where the bazel run command runs and use that in the generated directory names. Doing this delivers a pretty significant performance benefit on the second and further runs. Note that temp directories are wiped out between restarts on mac, but this should provide a health improvement.

Before (2nd run), about ~2 min

REPIN=1 bazel run @regression_testing_gradle//:pin  7.39s user 1.02s system 7% cpu 1:52.79 total

After (2nd run and every run after until bazel clean is run), ~30 seconds

REPIN=1 bazel run @regression_testing_gradle//:pin  6.25s user 0.77s system 25% cpu 27.258 total

The gradle home will be in a directory like this

smocherla@NLC2L54QQY rules_jvm_external % ls /private/var/tmp/_bazel_smocherla/536b5c8af4e86fad57fc24f39380ac8a/execroot/_main/bazel-out/_main~maven~regression_testing_gradle/darwin_arm64-fastbuild/bin/pin.runfiles/.gradle
caches  daemon  native

Additonally this speedens the up the unit tests significantly because the gradle daemon is re-used between tests.

Before

//tests/com/github/bazelbuild/rules_jvm_external/resolver/gradle:GradleResolverTest PASSED in 380.6s

Now

//tests/com/github/bazelbuild/rules_jvm_external/resolver/gradle:GradleResolverTest PASSED in 35.1s

I realize this could be controversial perhaps, so opening it in draft for comment.

Note that RJE_UNSAFE_CACHE will still be respected and it will use the gradle cache under user.home.

@shs96c
Copy link
Collaborator

shs96c commented Nov 4, 2025

I think we should leave the runfiles alone, but perhaps we can create a temporary cache in a well known location in $TMPDIR that has a deterministic name, so it'll be reshared between runs of gradle in the same repo? Much like how bazel calculates the output base.

@smocherla-brex
Copy link
Contributor Author

but perhaps we can create a temporary cache in a well known location in $TMPDIR that has a deterministic name, so it'll be reshared between runs of gradle in the same repo? Much like how bazel calculates the output base.

I like that idea, so I'll make that change.

@smocherla-brex smocherla-brex changed the title Use directory under runfiles for Gradle home Use persistent gradle home between invocations Nov 7, 2025
@smocherla-brex smocherla-brex marked this pull request as ready for review November 7, 2025 01:53
@smocherla-brex
Copy link
Contributor Author

Updated to use a persistent directory under /tmp, which has a hash generated from the repo directory under which bazel is run.

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

Two minor nits, but otherwise LGTM. Thank you!

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@shs96c shs96c merged commit ef4b80d into bazel-contrib:master Nov 23, 2025
6 checks passed
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.

2 participants