You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, all operations in Buffer operate with byte[] abstraction, meaning that any compound operation incurs overhead from reading and combining individual bytes.
Apart from (potentially non-optimizable) overhead, such an implementation also limits us from providing more efficient primitives -- e.g. SWAR-based indexOf.
It's worth considering VarHandles API for all our bulk operations that operate with anything bigger than byte, ideally isolated through a clear (internal) API boundary via a multi-release jar.
Here is my experiment from qwwdfsad/varhandles that gives a taste of a potential performance difference:
@Benchmark
fun write(): Buffer {
val buffer = Buffer()
for (long in data) {
buffer.writeLong(long)
}
return buffer
}
@Benchmark
fun writeVh(): Buffer {
val buffer = Buffer()
for (long in data) {
buffer.writeLongVh(long)
}
return buffer
}
@Benchmark
fun readLongArray(): LongArray {
val copy = buffer.copy()
for (index in data.indices) {
data[index] = copy.readLong()
}
return data
}
@Benchmark
fun readLongArrayVh(): LongArray {
val copy = buffer.copy()
for (index in data.indices) {
data[index] = copy.readLongVh()
}
return data
}
BulkWriteBenchmark.readLongArray avgt 5 329.162 ± 20.283 us/op
BulkWriteBenchmark.readLongArrayVh avgt 5 272.699 ± 7.798 us/op
BulkWriteBenchmark.write avgt 5 360.114 ± 26.572 us/op
BulkWriteBenchmark.writeVh avgt 5 241.212 ± 75.791 us/op
The text was updated successfully, but these errors were encountered:
Currently, all operations in
Buffer
operate withbyte[]
abstraction, meaning that any compound operation incurs overhead from reading and combining individual bytes.Apart from (potentially non-optimizable) overhead, such an implementation also limits us from providing more efficient primitives -- e.g. SWAR-based indexOf.
It's worth considering
VarHandles
API for all our bulk operations that operate with anything bigger than byte, ideally isolated through a clear (internal) API boundary via a multi-release jar.Here is my experiment from
qwwdfsad/varhandles
that gives a taste of a potential performance difference:The text was updated successfully, but these errors were encountered: