-
Notifications
You must be signed in to change notification settings - Fork 613
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
Introduce Chunk.ByteBuffer #1032
Conversation
Benchmark results:
|
JByteBuffer.wrap(c.values, c.offset, c.length) | ||
case c: Chunk.ByteBuffer => | ||
val b = c.buf.asReadOnlyBuffer | ||
if (c.offset == 0 && b.position == 0 && c.size == b.limit) b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that this actually saves a lot. This trick is inspired by scodec.bits.ByteVector
.
// } | ||
|
||
// "map.long => long" in forAll { c: Chunk[Long] => (c map (1 +)).toArray shouldBe (c.toArray map (1 +)) } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented because #1033.
second.position(n + offset) | ||
(ByteBuffer(first), ByteBuffer(second)) | ||
} | ||
override def map[O2](f: Byte => O2): Chunk[O2] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't benchmarked this against other plausible implementations. I think this will be faster than bulk-getting the array and mapping that, but I haven't proven it.
@ChristopherDavenport, @rossabaker looks great to me. thanks for this. lets take @mpilquist eyes on this before its merged ok ? |
Optimization for streams sourced from and sunk to
ByteBuffer
s. This avoids copying bytes on direct buffers, and the overhead of wrapping and unwrapping array-backed buffers.Moves
.toByteBuffer
operation toChunk
withByte
evidence.Brings back some properties for
Chunk
, and tests the new implementation.