GROOVY-10307: add JMH benchmarks for Grails-like invokedynamic pain points#2385
Merged
paulk-asert merged 5 commits intoapache:masterfrom Feb 27, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new set of JMH benchmarks under subprojects/performance to reproduce Grails-like invokedynamic performance regressions, focusing on metaclass invalidation patterns (ExpandoMetaClass churn, category enter/exit, dynamic dispatch mechanisms, and composite “request cycle” scenarios).
Changes:
- Introduces
MetaclassChangeBenchto benchmark ExpandoMetaClass updates, metaclass replacement, and multi-class invalidation cascades. - Introduces
CategoryBenchto benchmarkuse(Category)scope patterns and their invalidation overhead. - Introduces
DynamicDispatchBenchandGrailsLikePatternsBenchto cover Grails-style dynamic dispatch building blocks and composite application flows.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/MetaclassChangeBench.groovy | Benchmarks metaclass churn and replacement patterns affecting indy call sites. |
| subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/CategoryBench.groovy | Benchmarks category scope usage patterns and their impact on dispatch/invalidation. |
| subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/DynamicDispatchBench.groovy | Benchmarks methodMissing/propertyMissing/invokeMethod/expando-injection and def-typed dispatch. |
| subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/GrailsLikePatternsBench.groovy | Benchmarks composite, Grails-like request/service/domain/view rendering patterns with/without churn. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/MetaclassChangeBench.groovy
Outdated
Show resolved
Hide resolved
subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/DynamicDispatchBench.groovy
Outdated
Show resolved
Hide resolved
subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/DynamicDispatchBench.groovy
Outdated
Show resolved
Hide resolved
subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/grails/CategoryBench.groovy
Show resolved
Hide resolved
subprojects/performance/src/jmh/groovy/org/apache/groovy/perf/grails/CategoryBench.groovy
Show resolved
Hide resolved
…oints Add 43 JMH benchmarks across 4 files targeting the metaclass invalidation patterns that cause performance regression in Grails applications under invokedynamic. These complement the general-purpose benchmarks from apache#2381 by exercising the specific dynamic dispatch patterns identified in apache#2374 and apache#2377. New benchmark files: MetaclassChangeBench (11 benchmarks) - ExpandoMetaClass method addition during method dispatch - Metaclass replacement cycles - Multi-class invalidation cascade (change on ServiceA invalidates ServiceB/C) - Burst-then-steady-state (simulates Grails startup then request handling) - Property access and closure dispatch under metaclass churn CategoryBench (10 benchmarks) - use(Category) blocks inside vs outside loops - Nested and simultaneous multi-category scopes - Collateral invalidation damage on non-category call sites - Category method shadowing existing methods DynamicDispatchBench (12 benchmarks) - methodMissing with single/rotating names (dynamic finders) - propertyMissing read/write (Grails params/session) - GroovyInterceptable invokeMethod interception (transactional services) - ExpandoMetaClass-injected method calls mixed with real methods - def-typed monomorphic and polymorphic dispatch GrailsLikePatternsBench (10 benchmarks) - Service chain: validation, CRUD, collection processing - Controller action: param binding, service call, model/view rendering - Domain validation with dynamic property access (this."$field") - Configuration DSL with nested @DelegatesTo closures - Markup builder with nested tag/closure rendering - Full request cycle simulation with and without metaclass churn Run with: ./gradlew perf:jmh -PbenchInclude=perf
35a08fd to
aa5fdd3
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2385 +/- ##
==================================================
- Coverage 66.7263% 66.7220% -0.0043%
Complexity 29863 29863
==================================================
Files 1382 1382
Lines 116215 116215
Branches 20508 20508
==================================================
- Hits 77546 77541 -5
- Misses 32321 32326 +5
Partials 6348 6348 🚀 New features to boost your workflow:
|
Move the 4 Grails-like benchmark files into org.apache.groovy.perf.grails subpackage and add a matrix strategy to the jmh-perf and jmh-perf-classic workflows so core and grails benchmarks run as parallel CI jobs, each with its own 60-minute budget. Restore original @fork(2) and @measurement(iterations=5) settings now that the benchmarks have dedicated time slots.
Contributor
|
LGTM |
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.
https://issues.apache.org/jira/browse/GROOVY-10307
Follow-up to #2381 - adds 43 JMH benchmarks specifically targeting the metaclass invalidation patterns that cause performance regression in Grails applications under invokedynamic. While #2381 covers general Groovy language features, these benchmarks exercise the specific dynamic dispatch pain points identified during the optimization work in #2374 and #2377.
Run with:
./gradlew perf:jmh -PbenchInclude=perfBenchmark Files
MetaclassChangeBenchCategoryBenchuse(Category)blocks inside vs outside loops, nested and simultaneous multi-category scopes, collateral invalidation damage on non-category call sites, category method shadowingDynamicDispatchBenchGrailsLikePatternsBenchthis."$field"), configuration DSL with nested@DelegatesToclosures, markup builder with nested tag/closure rendering, full request cycle simulation43 benchmarks total, all using proper
Blackholeconsumption and@Setup(Level.Iteration)metaclass cleanup where appropriate.Pain Points Exercised
These benchmarks target the root cause identified in #2374 and #2377: global SwitchPoint invalidation when any metaclass changes. In baseline Groovy, every metaclass modification (ExpandoMetaClass method addition, category enter/exit, metaclass replacement) triggers
invalidateSwitchPoints(), which invalidates ALL invokedynamic call sites across the entire application.Metaclass Invalidation Patterns (MetaclassChangeBench)
The primary pain point. Each benchmark includes a baseline (no metaclass changes) for direct comparison:
Category Scope Patterns (CategoryBench)
Every
use(Category) { }triggers two SwitchPoint invalidations (enter + exit):Dynamic Dispatch Patterns (DynamicDispatchBench)
The building blocks of Grails' convention-based model:
Composite Grails Patterns (GrailsLikePatternsBench)
Realistic multi-layer patterns combining closures, dynamic dispatch, property access, and delegation:
@DelegatesToclosures with DELEGATE_FIRST resolution