GROOVY-12162: Harden and extend bytecode peephole optimization#2707
GROOVY-12162: Harden and extend bytecode peephole optimization#2707daniellansun wants to merge 3 commits into
Conversation
0ce2212 to
58dcf7a
Compare
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: cc7a492 | Previous: c76e8dc | Ratio |
|---|---|---|---|
org.apache.groovy.bench.StaticMethodCallIndyBench.staticChain_groovyCS |
2523.685772398189 ops/ms |
1595.6378191431031 ops/ms |
1.58 |
org.apache.groovy.bench.StaticMethodCallIndyBench.staticChain_java |
2520.3046195893407 ops/ms |
1595.5729626739744 ops/ms |
1.58 |
org.apache.groovy.bench.AryBench.java ( {"n":"1000"} ) |
0.1193460639887132 ms/op |
0.056632317821343335 ms/op |
2.11 |
org.apache.groovy.bench.CalibrationBench.memoryPointerChase |
993.5820446000793 us/op |
507.29968992095434 us/op |
1.96 |
This comment was automatically generated by workflow using github-action-benchmark.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2707 +/- ##
==================================================
+ Coverage 69.1120% 69.2369% +0.1249%
- Complexity 34251 34685 +434
==================================================
Files 1537 1540 +3
Lines 129403 130312 +909
Branches 23526 23755 +229
==================================================
+ Hits 89433 90224 +791
- Misses 31944 31980 +36
- Partials 8026 8108 +82
🚀 New features to boost your workflow:
|
JMH summary — classic (commit
|
| Group | Speedup | Calibrated | n |
|---|---|---|---|
| bench | 0.972 × | 1.025 × | 84 |
| core | 1.043 × | 1.013 × | 77 |
| grails | 1.017 × | 1.045 × | 80 |
Runner calibration (this run vs baseline hardware): bench 0.96× (26 rulers) · core-ag 1.08× (3 rulers) · core-hz 0.98× (3 rulers) · grails-ad 0.96× (3 rulers) · grails-ez 0.98× (3 rulers)
Baseline: dev/bench/jmh/<part>/classic/data.js on gh-pages, trailing 90 days. Daily dashboard · Per-suite raw data
JMH summary — indy (commit
|
| Group | Speedup | Calibrated | n |
|---|---|---|---|
| bench | 0.985 × | 0.991 × | 84 |
| core | 4.283 × | 3.763 × | 77 |
| grails | 2.199 × | 2.313 × | 80 |
⚠️ Runner speed differs ≥15% from the historical baseline hardware for: core-hz. Raw speedups are not meaningful for those parts — use the calibrated column.
Runner calibration (this run vs baseline hardware): bench 0.99× (26 rulers) · core-ag 1.09× (3 rulers) · core-hz 1.20× (3 rulers) · grails-ad 0.97× (3 rulers) · grails-ez 0.93× (3 rulers)
Baseline: dev/bench/jmh/<part>/indy/data.js on gh-pages, trailing 90 days. Daily dashboard · Per-suite raw data
bf2f825 to
1af9d64
Compare
1af9d64 to
39bc3fc
Compare
|
If no one objects to this PR, I'll merge it this weekend. |
|
AI read:
|
| 'ILOAD 0', | ||
| 'INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;', | ||
| 'INVOKEVIRTUAL java/lang/Long.longValue ()J', | ||
| 'LRETURN', |
There was a problem hiding this comment.
actually we could compress this to ILOAD0; I2L; LRETURN.
There was a problem hiding this comment.
I’d rather not. Integer.valueOf + Long.longValue must fail at runtime on the
wrong receiver (CCE / ICCE path). Rewriting to I2L would silently change
semantics. Mismatched unbox stays intact on purpose.
There was a problem hiding this comment.
I was going by the test, and here no wrong receiver is possible. You cannot get a CCE from an int using valueOf and not from longValue from the resulting instance. Though I wonder in what situation we would even emit that kind of code. For long l = 1? I think that would directly use I2L.
There was a problem hiding this comment.
You’re right — thanks for pushing on this.
With a pending Integer.valueOf the receiver is always Integer, so there is
no data-dependent “wrong receiver” CCE path worth preserving. Real classgen
already uses I2L for long l = intExpr; the box+Long.longValue form in the
test was artificial.
Done: pending box(P) followed by unbox-as-Q now rewrites to the matching
JVM conversion (I2L / L2I / I2F / …), including cross-wrapper cases such as
Integer.valueOf + Long.longValue. Same-type cancel is unchanged; Boolean is
still excluded from numeric conversion.
Agreed — same situation, opposite decisions. We settled on preserve CCE on both paths (Java-like; matches the void-RETURN intent). Change: Tests:
|
8741332 to
910982c
Compare
|
@blackdrag @paulk-asert |
|
✅ All tests passed ✅🏷️ Commit: cc7a492 Learn more about TestLens at testlens.app. |



https://issues.apache.org/jira/browse/GROOVY-12162