question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use ByteVectorChunk?

See original GitHub issue

ByteVectorChunk is a type of Chunk[Byte] which is better optimized for avoiding copies. Based on our experience with byte copying in scalaz-stream, I have a feeling this will be a big win for us.

But it only exists in fs2-1.0-SNAPSHOT. We should think about how we want to cut over, or whether we want to kindly ask for an fs2-0.10 so we can start building on that.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
rossabakercommented, Dec 17, 2017

Here’s a crude benchmark for concatenating some chunks and rendering it to an array for writing.

package org.http4s.bench

import fs2._
import fs2.interop.scodec.ByteVectorChunk
import org.openjdk.jmh.annotations._
import scodec.bits.ByteVector

@Fork(2)
@Threads(1)
@State(Scope.Benchmark)
@BenchmarkMode(Array(Mode.Throughput))
class BytesBench {
  val bs: Array[Byte] = "The quick brown fox jumped over the lazy dog.".getBytes("UTF-8")

  @Benchmark def byteVectorChunk = {
    val s = Segment.chunk(ByteVectorChunk(ByteVector.view(bs))) ++
      Segment.chunk(ByteVectorChunk(ByteVector.view(bs))) ++
      Segment.chunk(ByteVectorChunk(ByteVector.view(bs))) ++
      Segment.chunk(ByteVectorChunk(ByteVector.view(bs))) ++
      Segment.chunk(ByteVectorChunk(ByteVector.view(bs)))
    s.force.toArray
  }

  @Benchmark def bytes = {
    val s = Chunk.bytes(bs).toSegment ++
      Chunk.bytes(bs).toSegment ++
      Chunk.bytes(bs).toSegment ++
      Chunk.bytes(bs).toSegment ++
      Chunk.bytes(bs).toSegment
    s.force.toArray
  }
}
[info] Benchmark                    Mode  Cnt       Score       Error  Units
[info] BytesBench.byteVectorChunk  thrpt   40  350288.096 ± 12782.808  ops/s
[info] BytesBench.bytes            thrpt   40  470374.904 ± 19307.606  ops/s
0reactions
rossabakercommented, Mar 12, 2018

Yes, it will.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ByteVector - scodec
An immutable vector of bytes, backed by a balanced binary tree of chunks. ... Use copy to copy all underlying bytes to a...
Read more >
ByteVectorChunk - javadoc.io
Converts this chunk to a Chunk.Floats , allowing access to the underlying array of elements. If this chunk is already backed by an...
Read more >
scodec-bits/ByteVector.scala at main - GitHub
An immutable vector of bytes, backed by a balanced binary tree of chunks. ... Note: if an `n`-byte vector is required, use the...
Read more >
scheme-bytestructures: Guile library spotlight | Vijay Marupudi
In this post, we will take a quick look at scheme-bytestructures , a library for reading and writing structured binary data in Guile...
Read more >
scalaz-stream: how to chunk with concatenation?
I think you could simplify this a bit using take , last and scanMonoid def byteChunk(n: Int): Process1[ByteVector, ByteVector] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found