zulkar opened a new pull request, #2380:
URL: https://github.com/apache/maven-resolver/pull/2380

   
   ## Summary
   
   `DefaultArtifactResolver.resolve()` calls 
`RemoteRepositoryFilter.acceptArtifact()` for every remote repository of
   a request before it checks the workspace and the local repository. Resolver 
2.x enables the `prefixes` and
   `groupId` filter sources by default, so this runs in every default Maven 
build. In a large build nearly every
   request is a local hit, which means one filter call per remote repository 
for an artifact that's already on disk.
   
   On a 1667-module project this change removes about 26 % of the allocation of 
dependency resolution and 7 % of its
   wall time with a warm local repository.
   
   This changes observable behaviour (see below). I asked about it on 
[email protected] first and haven't had an
   answer yet, so I'm opening the PR to make the discussion concrete.
   
   ## Change
   
   Only release versions are affected. Snapshots, `RELEASE` and `LATEST` keep 
the current order, because their
   version resolution reads metadata from the accepted repositories. For a 
release version:
   
   - The workspace check and the local repository lookup move ahead of the 
filter. That early lookup uses all
     repositories of the request, not only the accepted ones.
   - The filter then runs once: it checks that the repository the local copy 
came from is enabled and accepted. A
     locally installed artifact has no such repository, so it gets no filter 
call.
   - Version resolution doesn't run when the artifact resolves from the 
workspace or the local repository.
   - If the filter rejects the local copy's repository, the previous path runs 
unchanged. On a local miss it runs
     too, but it reuses the result of the first lookup, so a miss still costs 
one `LocalRepositoryManager.find()`.
   
   ## Behaviour
   
   What stays the same: the resolved file, the repository reported in 
`ArtifactResult`, and the rule that a local
   copy cached from a repository the filter rejects is not used.
   
   What changes:
   
   - An artifact that resolves from the workspace or the local repository no 
longer carries an
     `ArtifactFilteredOutException` for each rejected repository. Nothing was 
contacted for it.
   - `VersionResolver.resolveVersion()` isn't called for such an artifact. 
Maven's `VersionResolver`
     (`maven-resolver-provider`) returns a plain release version unchanged and 
reads no metadata for it, so the call
     had no effect there. A custom implementation could behave differently. I 
don't know of one; neither Maven nor the
     IntelliJ IDEA Maven server replaces it.
   
   ## Tests
   
   - `testResolveRemoteArtifactSkipsFilterForDisabledRepositoryPolicy` asserted 
that the local lookup gets the
     filtered repository list. The lookup now runs first, so I removed that 
assertion. The test keeps its main check
     (no `ArtifactFilteredOutException` for a repository with a disabled 
policy) and still checks that a local miss
     costs one lookup.
   - New 
`testResolveLocalArtifactFromAcceptedRepositoryRecordsNoFilteredOutRepositories`:
 a copy cached from an
     accepted repository resolves without a download and without 
`ArtifactFilteredOutException`. It fails on master;
     that's the behaviour change.
   - New `testResolveLocalArtifactFromRejectedRepositoryIsNotUsed`: a copy 
cached from a rejected repository isn't
     used, and the result has an `ArtifactFilteredOutException`. It passes on 
master too, so this guarantee is kept.
   
   `mvn -Prun-its verify`: 2779 tests, 0 failures, 147 skipped; invoker IT 
passed.
   
   ## Benchmark
   
   - Maven 3.10.2 with Resolver master `3bfffc10`, without and with the change. 
Only the Resolver jars differ.
   - A synthetic project with 1667 modules and about 475 declared dependencies 
each. settings.xml declares 10 remote
     repositories; the dependency POMs add more.
   - A core extension (`-Dmaven.ext.class.path`) resolves the dependencies of 
every reactor project with
     `ProjectDependenciesResolver.resolve(new 
DefaultDependencyResolutionRequest(project, session))` on 12 threads,
     then Maven runs `validate`. No plugin runs, nothing compiles. The 
extension reports the wall time, and the CPU
     time and allocated bytes of the 12 resolver threads 
(`com.sun.management.ThreadMXBean`). Young GC is what young
     and mixed collections reclaimed, from `-Xlog:gc`. Heap `-Xmx16g`.
   - 2,535,614 artifact resolutions per run. The local repository holds 1,516 
jars and 4,771 POMs (1.1 GB).
   - Warm: each run starts from a copy of the same filled local repository. 
Clean: each run starts from an empty
     local repository, so its wall time includes the download of 1.1 GB.
   - Median of 3 interleaved runs on an Apple M-series laptop. In brackets: the 
difference to master.
   
   Warm local repository:
   
   | metric | master | this change | this change + #2379 |
   |---|---|---|---|
   | allocated, GB | 403.7 | 299.0 (−25.9 %) | 296.4 (−26.6 %) |
   | young GC, GB | 425.8 | 319.7 (−24.9 %) | 317.8 (−25.4 %) |
   | GC pauses | 183 | 168 (−8.2 %) | 172 (−6.0 %) |
   | GC pause time, s | 2.8 | 2.6 (−7.1 %) | 2.6 (−7.1 %) |
   | CPU, s | 864 | 799 (−7.5 %) | 821 (−5.0 %) |
   | wall, s | 113 | 105 (−7.1 %) | 105 (−7.1 %) |
   
   Clean local repository:
   
   | metric | master | this change | this change + #2379 |
   |---|---|---|---|
   | allocated, GB | 404.2 | 302.2 (−25.2 %) | 300.2 (−25.7 %) |
   | young GC, GB | 429.5 | 326.2 (−24.1 %) | 325.1 (−24.3 %) |
   | GC pauses | 194 | 175 (−9.8 %) | 169 (−12.9 %) |
   | GC pause time, s | 2.8 | 2.6 (−7.1 %) | 2.6 (−7.1 %) |
   | CPU, s | 853 | 803 (−5.9 %) | 850 (−0.4 %) |
   | wall, s | 384 | 378 (−1.6 %) | 409 (+6.5 %) |
   
   - Allocation is the reliable number: it varies by less than 1.5 GB between 
runs of one variant.
   - CPU and wall time vary by 40–60 s between runs of one variant. With a warm 
repository the ranges don't overlap:
     master 110–115 s, this change 99–109 s. With a clean repository the 
download dominates the wall time, so the
     difference is within the noise.
   - Every run resolved the same number of artifacts.
   - #2379 removes the per-call allocation of 
`DefaultRemoteRepositoryFilterManager` and doesn't change behaviour.
     With this change the filter runs only on local misses, so #2379 adds 
little on top; on its own it saves 5–6 %.
   - The benchmark ran on an earlier revision of this change, which did a 
second local lookup on a miss. Even with a
     clean repository a miss happens only once per unique artifact (about 6,300 
of 2.5M lookups, 0.25 %), so I don't
     expect that to move these numbers.
   
   I haven't measured this change in the IntelliJ IDEA import test yet.
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to