Skip to content

Add encodingToStrictByteString - #989

Closed
phadej wants to merge 1 commit into
masterfrom
strict-bs-builder
Closed

Add encodingToStrictByteString#989
phadej wants to merge 1 commit into
masterfrom
strict-bs-builder

Conversation

@phadej

@phadejphadej commented Jan 20, 2023

Copy link
Copy Markdown
Collaborator

This runs Builder to produce Strict ByteString directly, by making a mutable buffer and growing it exponentially.

This might be good or bad, better or worse than
LBS.toStrict . encodingToLazyByteString.
Latter allocates many small chunks, and copies once; encodingToStrictByteString makes a buffer exponentially, but copies data everytime.

TL;DR bytestrings Builder implementation allows to execute it into a contiguous buffer, i.e. strict bytestring.

(We could almost reuse the same trick to produce strict text as well, but we'd need to copy to unpin resulting bytearray)

@phadej
phadej requested a review from LysxiaJanuary 20, 2023 15:46
This runs Builder to produce Strict ByteString directly,
by making a mutable buffer and growing it exponentially.
This might be good or bad, better or worse than
LBS.toStrict . encodingToLazyByteString.
Latter allocates many small chunks, and copies once;
encodingToStrictByteString makes a buffer exponentially,
but copies data everytime.
@Lysxia
Lysxiaforce-pushed the strict-bs-builder branch from f3ad3d7 to 40cc0f8CompareJuly 2, 2026 22:42
@phadej

Copy link
Copy Markdown
CollaboratorAuthor

Please don't merge this. This wasn't any more efficient than serializing to lazy bytestring and then converting to strict one if needed.

@phadejphadej closed this Jul 6, 2026
@Lysxia
Lysxia deleted the strict-bs-builder branch August 25, 2026 17:38
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@phadej