-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential missed optimization in C2 JIT compiler #10609
Comments
Thanks @zijian-yi for the report. We will have a look. A minor side note for future performance reports - for Java benchmarking, especially micro benchmarks there is the jmh harness. https://openjdk.org/projects/code-tools/jmh/ a harness that helps to write benchmarks like you did here. There are many advantages of jmh - too many to enumerate them here in a simple comment but the most important one is that it makes benchmarking very small programs more reliable. The reproducer you shared is very small - a micro benchmark. Such programs tend to behave sometimes very non-intuitive with JVMs. If you have not heard of jmh yet maybe consider a short tutorial - https://www.baeldung.com/java-microbenchmark-harness . Do you maybe have free cycles to port your reproducer to a jmh micro before we have a look ? |
Thanks for the advice @davleopo . I have heard of the tool but haven't used it much. package org.sample;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)
public class Sum {
private static double sum = 1.0;
private static double comp = 0.1;
static double twoSumLow(double a, double b, double sum) {
final double bVirtual = sum - a;
return (a - (sum - bVirtual)) + (b - bVirtual);
}
@Benchmark
public void add() {
final double newSum = (sum % comp);
comp += twoSumLow(0.1, comp, newSum);
sum += comp;
}
} Reuslts:
|
@zijian-yi thanks for porting this to jmh. We will have a look. |
Thank you for the reproducer. We found that the floating point modulo operation causes the slowdown. This is tracked internally as [GR-61951] |
Describe the issue
Potential missed optimization in GraalVM C2 JIT compiler
Steps to reproduce the issue
Here is the program:
Run the program with C1 and C2 respectively:
Below is the result I got on my machine (the exact numbers vary depending on the machine, but the performance difference should be noticeable, try increasing N if not):
It looks like Oracle 23 (HotSpot JIT compiler) adds some new optimization(s), making the program run much faster. Such optimization(s) are not present in GraalVM yet.
Describe GraalVM and your environment:
The text was updated successfully, but these errors were encountered: