GROOVY-10307: Add targeted JMH benchmarks for SwitchPoint invalidation#2390
Merged
paulk-asert merged 2 commits intoapache:masterfrom Mar 4, 2026
Merged
Conversation
2cda0d5 to
46bf5e8
Compare
46bf5e8 to
e910285
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2390 +/- ##
==================================================
+ Coverage 66.7450% 66.7468% +0.0017%
- Complexity 29848 29849 +1
==================================================
Files 1382 1382
Lines 116130 116130
Branches 20471 20471
==================================================
+ Hits 77511 77513 +2
+ Misses 32286 32284 -2
Partials 6333 6333 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds new JMH benchmarks under org.apache.groovy.perf.grails to reproduce and quantify the invokedynamic regression related to global SwitchPoint invalidation seen in Grails 7 apps (GROOVY-10307), focusing on metaclass churn and Grails-like workloads.
Changes:
- Introduces
CallSiteInvalidationBenchto measure cross-type vs same-type invalidation and multi-call-site scaling. - Introduces
MetaclassVariationBenchto model GORM-like per-instanceExpandoMetaClassbehavior and static metaclass injection patterns. - Introduces
GrailsWorkloadBenchto model higher-level Grails workload patterns (closure chains, delegation, GStrings, dynamic property access) with periodic invalidation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/grails/CallSiteInvalidationBench.groovy | New focused benchmarks for SwitchPoint invalidation impact on hot call sites. |
| subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/grails/MetaclassVariationBench.groovy | New benchmarks for shared vs per-instance metaclass dispatch and GORM-like injection patterns. |
| subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/grails/GrailsWorkloadBench.groovy | New workload-style benchmarks derived from Grails demo regression patterns, with/without invalidation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...ts/performance/src/jmh/groovy/org/apache/groovy/perf/grails/CallSiteInvalidationBench.groovy
Outdated
Show resolved
Hide resolved
...ects/performance/src/jmh/groovy/org/apache/groovy/perf/grails/MetaclassVariationBench.groovy
Show resolved
Hide resolved
...ects/performance/src/jmh/groovy/org/apache/groovy/perf/grails/MetaclassVariationBench.groovy
Show resolved
Hide resolved
subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/grails/GrailsWorkloadBench.groovy
Show resolved
Hide resolved
subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/grails/GrailsWorkloadBench.groovy
Show resolved
Hide resolved
Remove unused ExpandoMetaClass import from CallSiteInvalidationBench. Clarify Javadoc on dynamicFinderCalls and mixedCompiledAndDynamicFinders to state that injection cost is intentionally included since these model per-request GORM behavior. Replace System.nanoTime() with a deterministic counter for metaclass property name variation in fullAnalysisWithInvalidation to eliminate unrelated overhead and improve run-to-run comparability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds three new JMH benchmark classes in
org.apache.groovy.perf.grailsthat reproduce the real-world invokedynamic performance regression observed in Grails 7 applications (GROOVY-10307).Benchmark Classes
CallSiteInvalidationBench (11 benchmarks)
Tests the core SwitchPoint invalidation mechanism - the root cause of the regression. Demonstrates that modifying ANY metaclass triggers global invalidation affecting ALL call sites:
Key result:
baselineHotLoop(0.49ms) vscrossTypeInvalidationEvery1000(467ms) = ~950x overheadMetaclassVariationBench (9 benchmarks)
Tests GORM-like patterns where domain classes get per-instance ExpandoMetaClass enhancements:
Key result:
baselineSharedMetaclass(2.0ms) vsperInstanceMetaclass(420ms) = ~207x overheadGrailsWorkloadBench (14 benchmarks)
Tests patterns extracted from the grails7-performance-regression demo app's
PerformanceTestService:.findAll{}.collect{}.groupBy{}.collectEntries{})employees*.firstName)this."$field").count{},.sum{}, map building)Key result:
baselineCollectionClosureChain(199ms) vs with invalidation (1631ms) = ~8.2x overhead (matches demo app's observed 8.2x bootRun regression)Running
Related