-
Notifications
You must be signed in to change notification settings - Fork 1.5k
AvroWriteSupport: optimize String to Binary Conversion #2994
Copy link
Copy link
Closed
Labels
Description
Describe the enhancement requested
Currently AvroWriteSupport.fromAvroString calls Binary.fromCharSequence when converting String to Binary.
Binary.fromCharSequence is an order of magnitude slower than Binary.fromString when input is a String, this is because CharsetEncoder.encode() is much slower than String.getBytes(charset).
benchmark results:
Benchmark Mode Cnt Score Error Units
Benchmarks.fromCharSequence thrpt 25 5885347.328 ± 186669.738 ops/s
Benchmarks.fromString thrpt 25 71335979.492 ± 8800704.044 ops/s
benchmark code:
public class Benchmarks {
private static final String string = RandomStringUtils.randomAlphanumeric(100);
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void fromCharSequence(Blackhole blackhole) {
blackhole.consume(Binary.fromCharSequence(string));
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void fromString(Blackhole blackhole) {
blackhole.consume(Binary.fromString(string));
}
}
Component(s)
Avro
Reactions are currently unavailable