-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
Description
Describe the issue
Performance regression of java.io.ByteArrayOutputStream.write().
Steps to reproduce the issue
Here is a JMH reproducer:
package org.sample;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
import java.io.ByteArrayOutputStream;
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
@Fork(3)
public class Buffer {
@Benchmark
public static void write() {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (int i = 0; i < 100; i++) {
buffer.write(1);
}
}
}Results on my machine:
GraalVM CE 25-dev+8.1:
Benchmark Mode Cnt Score Error Units
Buffer.write avgt 15 1545.649 ± 13.433 ns/op
Oracle GraalVM 23.0.2+7.1:
Benchmark Mode Cnt Score Error Units
Buffer.write avgt 15 1527.897 ± 2.722 ns/op
Oracle GraalVM 21.0.6+8.1:
Benchmark Mode Cnt Score Error Units
Buffer.write avgt 15 90.560 ± 0.629 ns/op
OracleJDK(HotSpot) 23.0.2+7-58:
Benchmark Mode Cnt Score Error Units
Buffer.write avgt 15 62.861 ± 0.270 ns/op
Environment:
- GraalVM and JDK versions are provided in the result.
- OS and Architecture: reproducible on Linux-AMD64 and macOS-ARM64.