Skip to content

Cache projectsUsingPlugin to fix O(N²) reactor scan - #427

Open
gnodet wants to merge 1 commit into
masterfrom
quick-fix/cache-projects-using-plugin
Open

Cache projectsUsingPlugin to fix O(N²) reactor scan#427
gnodet wants to merge 1 commit into
masterfrom
quick-fix/cache-projects-using-plugin

Conversation

@gnodet

@gnodet gnodet commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Cache the projectsUsingPlugin list in the first reactor project's plugin context on first invocation
  • The list is invariant during a build — which projects have the install plugin configured does not change between module invocations
  • Reduces O(N²) to O(N) total for the reactor scan

Problem

InstallMojo.execute() computes session.getProjects().stream().filter(this::usingPlugin).collect(toList()) on every module invocation. usingPlugin() calls getPluginsAsMap() for each project. In a 4383-module reactor, this produces ~19.2M filter evaluations (4383²).

JFR profiling shows this pattern as 5.6% of total CPU time, all in PluginContainer.getPluginsAsMap().

Test plan

  • All 14 existing tests pass
  • Verify on a large multi-module reactor build

🤖 Generated with Claude Code

InstallMojo.execute() computes the list of reactor projects using
the install plugin on every module invocation by streaming over all
projects and calling getPluginsAsMap() for each one. In a 4383-module
reactor, this produces ~19.2M filter evaluations (4383² calls).

JFR profiling shows this as 5.6% of total CPU time, all in
PluginContainer.getPluginsAsMap() called from usingPlugin().

Fix: cache the computed list in the first reactor project's plugin
context on first invocation. The list is invariant during a build —
which projects have the install plugin configured does not change
between module invocations. This turns O(N²) into O(N).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant