Skip to content

[Backport 4.0.x] Optimize computeLocations() and simplify ModelObjectPool location handling - #13042

Merged
gnodet merged 1 commit into
maven-4.0.xfrom
cherry-pick-13031-to-4.0.x
Sep 4, 2026
Merged

[Backport 4.0.x] Optimize computeLocations() and simplify ModelObjectPool location handling#13042
gnodet merged 1 commit into
maven-4.0.xfrom
cherry-pick-13031-to-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Backport of #13031 from master to maven-4.0.x.

Only the model.vm changes apply — DefaultModelObjectPool.java does not exist on maven-4.0.x (removed/refactored).

…dling (#13031)

Two targeted optimizations in the model building pipeline:

1. computeLocations(): replace Stream.concat().collect(toUnmodifiableMap)
   with HashMap.putAll() + Map.copyOf(). Also return oldlocs directly
   when newlocs is empty (avoids unnecessary Map.copyOf since base
   locations are already immutable). Add getLocations() accessor for
   direct map access.

2. ModelObjectPool.PoolKey: the original code used getLocationKeys() +
   getLocation(key) to iterate locations because getLocations() did not
   exist. Add getLocations() to the model and use Objects.equals() on the
   map directly, replacing both the per-key iteration in locationsEqual()
   and the separate locationsHashCode() helper. Remove redundant
   getLocationKeys() equality check (subsumed by map equality).

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Solid backport. The computeLocations() optimization correctly preserves merge semantics (newlocs overrides oldlocs via HashMap.putAll — equivalent to the previous Stream.concat with (v1, v2) -> v1). Skipping Map.copyOf(oldlocs) when newlocs is empty is safe because base.locations is always unmodifiable (set by a prior computeLocations() or Map.of()). New getLocations() accessor correctly exposes the already-unmodifiable map.

This review was generated by an AI agent, Hermès, on behalf of @gnodet.

@gnodet
gnodet merged commit 127b88f into maven-4.0.x Sep 4, 2026
23 checks passed
@gnodet
gnodet deleted the cherry-pick-13031-to-4.0.x branch September 4, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant