Accumulate streamDecrypt reads linearly, not quadratically (closes #21) #61

Merged
clawbot merged 1 commits from issue-21-streamdecrypt-linear-accumulation into next 2026-09-22 15:13:09 +02:00
1 Commits
Author SHA1 Message Date
sneak 880bd26d67 Accumulate streamDecrypt reads linearly, not quadratically (closes #21)
check / check (push) Successful in 35s
streamDecrypt reallocated and recopied its whole accumulation buffer on
every network read, so a chunk delivered as N reads cost O(chunk^2/read)
bytes copied — for a 4 MiB chunk, about a second of memory churn against
~20 ms of libsodium work, and the dominant cost of a large backup.

Incoming reads are now queued as-is with a running byte count and only
stitched into a contiguous buffer at each ENC_CHUNK_SIZE boundary, so
each received byte is copied once regardless of file size. A read that
straddles a boundary is split with a subarray view, its tail requeued.

Wire format, chunk framing, truncation detection, retry semantics, and
the per-chunk progress hook are unchanged; behaviour is identical. A new
test feeds a multi-chunk body through a ReadableStream in many small
1000-byte pieces — the fragmented-read path the other fixtures, which
deliver each body in one read, never exercised — and asserts the
plaintext is byte-identical and the chunk framing intact.

Model: opus-4-8
2026-09-22 12:57:59 +00:00