rearl opened a new issue, #590:
URL: https://github.com/apache/maven-build-cache-extension/issues/590

   ### Affected version
   
   1.3.0
   
   ### Bug description
   
   ## How it affects us
   
   Our multi-module build (78 modules, `mvn -T2 verify`, Maven 3.10.0, Java 25) 
runs on CI in a container with a fixed memory limit. With the build cache 
extension active, the memory used by the Maven JVM itself keeps growing as the 
build goes on, and is only freed when Maven exits:
   
   - the live heap after GC grows by about 35 MB per module, reaching 2.76 GB 
at the end of the build, and no garbage collection frees it;
   - full builds that can't restore most modules from the cache were killed for 
running out of memory, so we had to raise the container limit from 6 GiB to 10 
GiB;
   - `-Dmaven.build.cache.skipCache=true` doesn't help: the memory still grows.
   
   The bigger the reactor, the more memory Maven needs, even though each 
module's work is finished long before the end of the build.
   
   ## Technical analysis
   
   *This analysis was carried out by an AI assistant (Claude), based on a heap 
dump of our build and the source code of the ‘maven-build-cache-extension’. I 
have checked the text, but to be honest I cannot comment on its technical 
accuracy.*
   
   `MojoParametersListener` stores every `MojoExecutionEvent` in 
`projectExecutions` (keyed by `MavenProject`) and never removes an entry. The 
map is read only once per project, in 
`BuildCacheMojosExecutionStrategy.saveToCache()`, to record that project's mojo 
properties. After that the entry is no longer needed, but it keeps each event, 
its mojo instance and everything the mojo references reachable until Maven 
exits.
   
   A heap dump taken near the end of the build shows the effect:
   
   - `projectExecutions` held 701 `MojoExecutionEvent`s, with about 870 MB of 
reachable objects, mostly POM models: 6,766 `MavenProject` and 13,975 `Model` 
instances for 78 modules, and 1.15 M `Dependency` objects.
   - The main contributors were the 16 `license-maven-plugin` `add-third-party` 
mojos (one per module that runs it). Each mojo's 
`DefaultThirdPartyHelper.artifactCache` holds a full `MavenProject` for every 
dependency of its module, about 3,700 projects in total, plus their parent 
POMs. Without the listener's reference, each mojo and its cache would become 
garbage once its module finishes.
   
   `skipCache=true` doesn't help, because the cache state is still 
`INITIALIZED` and the listener keeps recording. Only 
`-Dmaven.build.cache.enabled=false` stops the recording (MBUILDCACHE-123 / 
#288).
   
   Suggested fix: drop the project's events once its executions are done. For 
example, add `MojoParametersListener.remove(MavenProject)` and call it in a 
`finally` block at the end of `BuildCacheMojosExecutionStrategy.execute()`, 
after `saveToCache()`. Forked executions use their own `MavenProject` instances 
as keys, so they would not be affected. A lighter alternative is to keep only 
the property values that `recordMojoProperties()` needs instead of the whole 
event, but that means reading the mojo fields before the save.


-- 
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