gnodet opened a new pull request, #12653: URL: https://github.com/apache/maven/pull/12653
## Summary - **Add Builder getters** to generated model classes (`model.vm`) — enables reading builder fields through the base chain without calling `build()`, supporting deferred materialization across pipeline stages - **Add `*ToBuilder` merger variants** (`merger.vm`) — returns `Builder` instead of calling `build()`, letting callers accumulate changes across multiple merge passes without intermediate allocations - **Defer `build()` in `DefaultDependencyManagementInjector`** — accumulates merged dependencies as `Builder` objects, calling `build()` only once per modified dependency at the end of the loop - **Optimize `computeLocations()`** — replaces `Stream.concat().collect(Collectors.toUnmodifiableMap(...))` with `HashMap.putAll()` + `Map.copyOf()`, and returns `oldlocs` directly when `newlocs` is empty (avoids unnecessary `Map.copyOf` since the base map is already immutable) - **Precompute `locationsHashCode`** — cached at build time in the generated constructor, used by `DefaultModelObjectPool.PoolKey` for fast inequality checks before full map comparison - **Optimize `PoolKey.locationsEqual()`** — uses direct `getLocations()` map comparison instead of iterating individual keys, with fast-path for both-empty maps (common for imported deps) - **Add `addLocationInformation` API to `XmlReaderRequest`** — wired through `DefaultModelXmlFactory` for future use in skipping location tracking on imported BOM POMs ### Context JFR profiling on a 4,383-module reactor shows 37% CPU in `ModelObjectPool` (dependency interning), 18% in `Dependency` immutable builders, and 2.3 GB allocated in `KeyValueHolder` from `computeLocations()`. Each `Dependency` passes through ~7 pipeline stages, each calling `build()` which allocates a new immutable object + recomputes location maps + calls `processObject()`. This PR targets the three hottest code paths: 1. **Redundant `build()` calls** — deferred via Builder getters and ToBuilder merger variants 2. **`computeLocations()` stream overhead** — replaced with HashMap merge + early return 3. **`PoolKey` location comparison** — precomputed hash + direct map equality ## Test plan - [x] `mvn verify -B` passes across all reactor modules (all tests green) - [x] `FileToRawModelMergerTest` updated to exclude new `*ToBuilder` methods from reflection-based override check - [ ] Benchmark with JFR on large reactor to measure allocation reduction 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
