Skip to content

Avoid copying large data - #18

Merged
snshn merged 1 commit into
masterfrom
avoid-copying-large-data
Oct 16, 2026
Merged

snshn merged 1 commit into
masterfrom
avoid-copying-large-data

Conversation

@snshn

@snshn snshn commented Oct 16, 2026

Copy link
Copy Markdown
Member

set_data() takes impl Into<Vec<u8>>, so a Vec<u8> or String gets moved in
instead of copied (slices, arrays and string literals still work).

Serializing writes in chunks instead of building the whole data URL in
memory first; Display uses that, and so does the new write_to(), which
writes to any std::io::Write. encoded_len() gives the exact length of
the serialized data URL without serializing it.

Parsing base64 decodes straight from the input when it has no "%" escapes,
and forgiving-base64 decoding no longer makes a stripped copy of its input.
For a 10 MB payload, peak memory while parsing went from about 40 MB to
10 MB (just the result), and parsing got about a third faster.

The CLI writes its output as it encodes it.

@snshn
snshn merged commit df4c15c into master Oct 16, 2026
9 checks passed
Sign up for free to 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