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

   ## Summary
   
   `DefaultArtifactResolver` and `DefaultMetadataResolver` call the filter of
   `DefaultRemoteRepositoryFilterManager` for every artifact (or metadata) and 
every remote repository of a
   request. In Resolver 2.x the `prefixes` and `groupId` sources are enabled by 
default, so this filter is active
   in a default Maven build, and almost all calls end in "accepted".
   
   Today each call:
   
   - builds a stream and a `HashMap` of per-participant results 
(`Participants.acceptArtifact()` /
     `acceptMetadata()`),
   - walks that map twice in `Consensus` and joins a reasoning string, which is 
empty when all participants accept.
   
   This change removes that per-call garbage. On a 1667-module build it removes 
5–6 % of the allocation of
   dependency resolution.
   
   ## Change
   
   - `Participants` keeps the participants in an array and loops over it.
   - When all participants accept, it returns one shared `Consensus.ACCEPTED` 
instance.
   - `Consensus` keeps only the results that did not accept. `reasoning()` 
joins their reasoning when it is
     called, not when the result is built.
   
   ## Behaviour
   
   No change:
   
   ## Benchmark
   
   - Maven 3.10.2 with Resolver master `3bfffc10`, without and with this 
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))`, in a pool of
     12 threads, and 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`).
   - 2,535,614 artifact resolutions per run; the local repository holds 1,516 
jars and 4,771 POMs (1.1 GB).
   - Clean: each run starts from an empty local repository. Warm: each run 
starts from a copy of the same
     filled local repository.
   - Young GC is the sum of what young (and mixed) collections reclaimed, from 
`-Xlog:gc`.
   - Median of 3 runs, runs interleaved, Apple M-series laptop. In brackets: 
the change against master.
   
   | local repository | heap | allocated, GB | young GC, GB | GC pauses | CPU, 
s | wall, s |
   |---|---|---|---|---|---|---|
   | warm | 16 GB | 403.7 → 378.7 (−6.2 %) | 425.8 → 401.4 (−5.7 %) | 183 → 184 
(+0.5 %) | 864 → 811 (−6.1 %) | 113 → 102 (−9.7 %) |
   | clean | 16 GB | 403.1 → 381.6 (−5.3 %) | 428.0 → 405.2 (−5.3 %) | 201 → 
190 (−5.5 %) | 889 → 829 (−6.7 %) | 403 → 378 (−6.2 %) |
   | clean | 2 GB | 403.6 → 381.8 (−5.4 %) | 427.8 → 405.1 (−5.3 %) | 773 → 751 
(−2.8 %) | 834 → 796 (−4.6 %) | 408 → 396 (−2.9 %) |
   
   - The allocation is the reliable number: its spread within one variant is 
below 1.5 GB.
   - CPU and wall time vary by 40–60 s between runs of the same variant, which 
is the size of the effect. The
     clean wall time also includes the download of 1.1 GB.
   - The number of resolved artifacts is the same in all runs.
   
   In IntelliJ IDEA the performance change is even more significant. We build 
the dependency graph in verbose mode (`aether.conflictResolver.verbose`, 
`aether.dependencyManager.verbose`), which keeps the conflict losers and makes 
more artifact requests. In one import of the same project the Maven server 
process reclaimed 724.2 GB in young GC without the change and 576.0 GB with it 
(−20.5 %). That is a single run each; its wall time did not change beyond the 
noise.
   
   The IDE performance test imports the same project twice: the first launch 
fills a new local repository, the second launch is the measured one. The Maven 
server runs the same Maven 3.10.2 distributions, with `-Xmx16g`.
   
   
   
   | launch | metric | master | this change |
   |---|---|---|---|
   | first (warmup) | Maven server young GC, GB | 755.5 | 595.3 (−21.2 %) |
   | first (warmup) | GC pauses | 253 | 227 (−10.3 %) |
   | first (warmup) | GC pause time, s | 25.8 | 12.5 (−51.6 %) |
   | measured | Maven server young GC, GB | 724.2 | 576.0 (−20.5 %) |
   | measured | GC pauses | 190 | 164 (−13.7 %) |
   | measured | GC pause time, s | 14.2 | 13.2 (−7.0 %) |
   | measured | sync, s | 389.2 | 410.0 (+5.3 %) |
   | measured | dependency resolution, s | 371.6 | 392.4 (+5.6 %) |
   
   The GC traffic drops by a fifth. The wall times come from one run each, and 
on this machine a single run
   varies by more than 5 %, so they show no change in either direction.
   
   The resolving phase takes 60-80% of overall import time, so the change would 
be quite visible.
   <img width="1871" height="552" alt="image" 
src="https://github.com/user-attachments/assets/863153b2-3392-4b1a-8d2a-58a5c079de69";
 />
   
   
   
   - [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