gnodet commented on PR #12653:
URL: https://github.com/apache/maven/pull/12653#issuecomment-5150820140

   ## JFR-guided optimization (v3): `withImportedFrom` + 
`ConcurrentHashMap.newKeySet`
   
   JFR profiling on the 4383-module benchmark identified two remaining 
hotspots, now fixed in commit d30efb592e:
   
   ### CPU profile comparison (v2 → v3)
   
   | Component | v2 samples | v2 % | v3 samples | v3 % | Change |
   |-----------|-----------|------|-----------|------|--------|
   | **DependencyMgmtImporter** | **442** | **43.0%** | **143** | **20.4%** | 
**-68%** |
   | ↳ `updateWithImportedFrom` | 354 | 34.4% | 44 | 6.3% | **-88%** |
   | CopyOnWriteArraySet | 68 | 6.6% | 0 | 0.0% | **-100%** |
   | ModelValidator | 71 | 6.9% | 66 | 9.4% | same |
   | I/O (XML, Zip, Jar) | 78 | 7.6% | 86 | 12.3% | same |
   | Other | 369 | 35.9% | 406 | 57.9% | same |
   | **Total CPU samples** | **1028** | | **701** | | **-32%** |
   
   ### What was fixed
   
   **1. `updateWithImportedFrom` (was 35% of CPU)**
   
   Every BOM-imported dependency was rebuilt through 
`Dependency.newBuilder(dep, true).importedFrom(loc).build()` — triggering 
forceCopy (wraps all sub-lists into builders), build (unwraps back to 
immutable), and object pool interning — just to set one metadata field.
   
   Added `withImportedFrom(InputLocation)` + private copy constructor to 
`model.vm`. Shares all model fields by reference, bypasses Builder and object 
pool entirely.
   
   **2. `CopyOnWriteArraySet` (was 6.6% of CPU)**
   
   `ConsumerPomArtifactTransformer.deferDeleteFile()` added to a 
`CopyOnWriteArraySet<Path>` → O(n) `indexOfRange` scan + array copy per add. 
With 4383 modules: O(n²). Replaced with `ConcurrentHashMap.newKeySet()` → O(1).
   
   ### Wall-clock benchmark (4383 modules, `mvn validate`)
   
   Wall-clock difference between v2 and v3 is within noise (~0.3s on a 14s 
benchmark) because:
   - BOM import runs once on the root POM, not on the critical path for 
parallel child processing
   - The parallel 4383-module build is I/O and scheduling dominated
   
   The cumulative improvement from rc-6 baseline remains **~27% faster**.


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