[data] Chunk fixes & benchmark#1001
Conversation
| */ | ||
| final override def isEmpty: Boolean = length == 0 | ||
|
|
||
| final override def knownSize: Int = length |
There was a problem hiding this comment.
This is quite important where other libraries may pre-allocate based on knowSize.
| * a new Chunk with the last n elements removed | ||
| */ | ||
| override def dropRight(n: Int): Chunk[A] = | ||
| final override def dropRight(n: Int): Chunk[A] = |
There was a problem hiding this comment.
It's easier to remove final than add it (for bin compat). We can change later if we need to override in a subclass.
| self match | ||
| case c: Indexed[B] @unchecked => c | ||
| case _ => Compact(toArrayInternal) | ||
| case _ => Compact(toArray) |
There was a problem hiding this comment.
This avoids matching on Indexed again
| case seq: IndexedSeq[A] => FromSeq(seq) | ||
| case _ => Compact(source.iterator.toArray(using erasedTag[A])) | ||
| case _ => | ||
| val array = source.iterator.toArray(using erasedTag[A]) |
There was a problem hiding this comment.
Iterators may produce an empty array. This shouldn't be an issue for Seqs.
| "Indexed" - { | ||
| "returns the same instance for Chunk.Indexed input" in { |
There was a problem hiding this comment.
We should probably have a Chunk.from that doesn't automatically compact in the main Chunk object.
| @@ -0,0 +1,243 @@ | |||
| package kyo.bench | |||
There was a problem hiding this comment.
I didn't use this to optimize anything yet, though it should be helpful.
| def setup(): Unit = | ||
| val intArray = Array.fill(size)(intFillFn) | ||
| intKyoChunk = Chunk.from(intArray) | ||
| intZioChunk = ZChunk.from(intArray) |
There was a problem hiding this comment.
ZIO's Chunk.from doesn't copy arrays. Seems quite dangerous.
fcfcefc to
ad741f4
Compare
|
it seems equality between different chunk types is broken: https://github.com/getkyo/kyo/actions/runs/12738165985/job/35500083525?pr=1001#step:6:4338 |
ad741f4 to
26adccf
Compare
26adccf to
4672a40
Compare
No description provided.