ResultChunkAssembler.accept decodes every buffered chunk when checking the assembled size and then decodes every chunk again when building the final byte array. The size pass at lib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:20 calls decodedBytes for each chunk, and the final assembly at lib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:26 calls decodedBytes again, converts each ByteArray to an Iterable<Byte>, flattens into boxed Byte values, and finally converts back to a primitive ByteArray. This is avoidable allocation and CPU work on the hot path for large streamed results, especially near the 64 MiB default limit.
Fix prompt: Store decoded bytes or per-chunk decoded sizes as chunks arrive so each chunk is decoded once. When the terminal chunk arrives, allocate a single output ByteArray of the known total size and copy each decoded chunk into it, or use ByteArrayOutputStream with the expected size. Keep the existing max-size guard, preserve mixed-encoding and monotonic-sequence validation, and add a regression test that confirms large base64 chunks are assembled without changing semantics.
ResultChunkAssembler.acceptdecodes every buffered chunk when checking the assembled size and then decodes every chunk again when building the final byte array. The size pass atlib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:20callsdecodedBytesfor each chunk, and the final assembly atlib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:26callsdecodedBytesagain, converts eachByteArrayto anIterable<Byte>, flattens into boxedBytevalues, and finally converts back to a primitiveByteArray. This is avoidable allocation and CPU work on the hot path for large streamed results, especially near the 64 MiB default limit.Fix prompt: Store decoded bytes or per-chunk decoded sizes as chunks arrive so each chunk is decoded once. When the terminal chunk arrives, allocate a single output
ByteArrayof the known total size and copy each decoded chunk into it, or useByteArrayOutputStreamwith the expected size. Keep the existing max-size guard, preserve mixed-encoding and monotonic-sequence validation, and add a regression test that confirms large base64 chunks are assembled without changing semantics.