Skip to content

SONARJAVA-7182 Replace frequently allocated streams with loops - #6349

Merged
aurelien-coet-sonarsource merged 2 commits into
masterfrom
ac/SONARJAVA-6910
Oct 15, 2026
Merged

aurelien-coet-sonarsource merged 2 commits into
masterfrom
ac/SONARJAVA-6910

Conversation

@aurelien-coet-sonarsource

@aurelien-coet-sonarsource aurelien-coet-sonarsource commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • Refactoring:
    • Replaced stream-based anyMatch calls in MethodMatchersList with a loop-based matchesAny helper
    • Replaced the Stream.of pipeline in JMethodSymbol.findOverridesInTypes with a for loop that breaks on first match

This will update automatically on new commits.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7182

@aurelien-coet-sonarsource aurelien-coet-sonarsource changed the title SONARJAVA-6910 Replace frequently allocated streams with loops SONARJAVA-7182 Replace frequently allocated streams with loops Oct 14, 2026
@aurelien-coet-sonarsource
aurelien-coet-sonarsource added this pull request to stack #6363 October 15, 2026 09:35
@aurelien-coet-sonarsource

Copy link
Copy Markdown
Contributor Author

Bechmark:

To assess the impact of the changes in this PR, a benchmark was run on a sample project (the core module in jOOQ, 2,217 Java files) before and after the changes.

The benchmark repeatedly analyzed the same 2,127 jOOQ Java files with unchanged rules and settings. Each version had ten measured scans at both 2 GB and 4 GB heaps, using fresh JVMs, plus three separate 4 GB Java Flight Recorder allocation profiles. JFR estimated allocated bytes by object class and call stack; GC logs measured collection activity and heap occupancy, while process sampling measured CPU and peak RSS. Results below are medians, and allocation volume represents cumulative traffic rather than retained memory.

Results:

Replacing Streams with loops in JMethodSymbol.findOverridesInTypes() and MethodMatchersList.matches() substantially reduced allocation traffic:

Median per scan Original Streams Loops Change
Total allocation 91.31 GB 82.39 GB −9.8%
Stream-object allocation 16.10 GB 7.89 GB −51.0%
Java analysis, 2 GB heap 103.9 s 101.1 s −2.7%
Java analysis, 4 GB heap 94.1 s 93.2 s −1.0%

Both modified methods had zero sampled Stream allocations after replacement. GC pause counts fell by approximately 8%, but total pause time and peak RSS changed little.

The clearest improvement was lower allocation volume, rather than lower peak memory or a reliably established speedup. Both versions produced identical analysis results.

@gitar-bot

gitar-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟢 Low risk · Replacing two stream pipelines with equivalent loops is narrowly scoped and reduces allocation without changing matching or override-selection behavior.

Replaces stream-based anyMatch calls in MethodMatchersList with a loop-based matchesAny helper, and swaps the Stream.of pipeline in JMethodSymbol.findOverridesInTypes for a for loop that breaks on first match. No issues found.

Verification Rules 2/2 met

Functional validation No results

Rules 2 passed 1 not applicable

✅ Internal artifact registries
✅ Repository license compliance

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@aurelien-coet-sonarsource
aurelien-coet-sonarsource marked this pull request as ready for review October 15, 2026 09:55
@sonarqube-next

Copy link
Copy Markdown
Contributor

@vdiez vdiez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@aurelien-coet-sonarsource
aurelien-coet-sonarsource merged commit 326bb6c into master Oct 15, 2026
20 checks passed
@aurelien-coet-sonarsource
aurelien-coet-sonarsource deleted the ac/SONARJAVA-6910 branch October 15, 2026 12:20
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.

2 participants