toLazyByteString

toLazyByteString :: Builder -> ByteString
bytestring Data.ByteString.Builder
Execute a Builder and return the generated chunks as a lazy ByteString. The work is performed lazy, i.e., only when a chunk of the lazy ByteString is forced.
toLazyByteStringWith :: AllocationStrategy -> ByteString -> Builder -> ByteString
bytestring Data.ByteString.Builder.Extra
Execute a Builder with custom execution parameters. This function is forced to be inlined to allow fusing with the allocation strategy despite its rather heavy code-size. We therefore recommend that you introduce a top-level function once you have fixed your strategy. This avoids unnecessary code duplication. For example, the default Builder execution function toLazyByteString is defined as follows. > {--} > toLazyByteString = > toLazyByteStringWith (safeStrategy smallChunkSize defaultChunkSize) empty In most cases, the parameters used by toLazyByteString give good performance. A sub-performing case of toLazyByteString is executing short (<128 bytes) Builders. In this case, the allocation overhead for the first 4kb buffer and the trimming cost dominate the cost of executing the Builder. You can avoid this problem using > toLazyByteStringWith (safeStrategy 128 smallChunkSize) empty This reduces the allocation and trimming overhead, as all generated ByteStrings fit into the first buffer and there is no trimming required, if more than 64 bytes are written.