Skip to content

fix(ctb): stream layer payloads to disk instead of storing them all in RAM - #10

Open
Jo-Con-El wants to merge 1 commit into
mainfrom
ender/ctb-streaming-encoder-oom-fix
Open

fix(ctb): stream layer payloads to disk instead of storing them all in RAM#10
Jo-Con-El wants to merge 1 commit into
mainfrom
ender/ctb-streaming-encoder-oom-fix

Conversation

@Jo-Con-El

Copy link
Copy Markdown
Contributor

CtbRleStreamingEncoder kept every layer's encoded bytes in memory for
the whole job, which OOMs on large 3DAA jobs at high resolution. Layers
now stream straight to a scratch file as they arrive (reordered if
needed) and finalize_to_path writes the non-encrypted CTB v5 container
straight to disk. Encrypted (v5enc) output still assembles in memory
at finalize time — its pointer table needs random access — but no
longer accumulates during the job itself.

…e job

CtbRleStreamingEncoder retained every layer's encoded (RLE+XOR) bytes in
a Vec for the entire lamination and only released them at finalize,
which OOMs on large 3DAA jobs at high resolution (retained bytes grow
linearly with layer count and never plateau). It now writes each
layer's payload straight to a scratch file as it arrives (with a small
out-of-order reorder buffer, since parallel post-processing can finish
layers out of index order) and keeps only a lightweight per-layer
record in memory. finalize_to_path streams the non-encrypted CTB v5
container straight to the destination file; encrypted (v5enc) output
still assembles in memory at finalize time, since its pointer table
needs random access, but no longer accumulates during the job itself.

build_ctb_container_bytes_with_progress is refactored to share this
streaming payload writer instead of triple-copying the payload region
(prepared Vec -> layer_payload_data -> out) on every non-streaming call
too.
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