Closed sschepens closed 2 months ago
Binary.fromCharSequence is an order of magnitud slower than Binary.fromString when input is a String:
Binary.fromCharSequence
Binary.fromString
String
Benchmarks.fromCharSequence thrpt 25 5885347.328 ± 186669.738 ops/s Benchmarks.fromString thrpt 25 71335979.492 ± 8800704.044 ops/s
Here is the code for the benchmarks:
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)); } }
Change AvroWriteSupport.fromAvroString() to use Binary.fromString when operating with string inputs.
AvroWriteSupport.fromAvroString()
Current tests should cover the change
No
Closes #2994
Rationale for this change
Binary.fromCharSequence
is an order of magnitud slower thanBinary.fromString
when input is aString
:Here is the code for the benchmarks:
What changes are included in this PR?
Change
AvroWriteSupport.fromAvroString()
to useBinary.fromString
when operating with string inputs.Are these changes tested?
Current tests should cover the change
Are there any user-facing changes?
No
Closes #2994