Skip to content

Stream proof serialization into the writer#819

Draft
jotabulacios wants to merge 1 commit into
mainfrom
perf/stream-proof-serialization
Draft

Stream proof serialization into the writer#819
jotabulacios wants to merge 1 commit into
mainfrom
perf/stream-proof-serialization

Conversation

@jotabulacios

Copy link
Copy Markdown
Collaborator

Stream proof serialization into the output writer

Motivation

When writing a proof to disk, the CLI serialized the whole proof into an in-memory
Vec<u8> and then wrote that buffer out. This holds two full copies of the proof in RAM
at once
— the proof struct plus its serialized bytes — roughly 2× the proof size at
write time.

For monolithic proofs the buffer is small, but continuation bundles grow with the number
of epochs, so for large blocks this duplicate buffer is several GB and becomes the process
memory peak — at large enough sizes it can OOM. It is a memory inefficiency, not a
correctness issue: the written proof was always valid.

Change

Replace bincode::serialize(&x) + writer.write_all(&bytes) with
bincode::serialize_into(&mut writer, &x) + writer.flush() in both proof-writing paths
(cmd_prove and cmd_prove_continuation). The encoding streams straight into the
BufWriter, so only the proof itself — not a second serialized copy — is resident during
the write. Output is byte-identical; existing proofs and verification are unaffected.

Impact (measured)

100-transfer ethrex block, --epoch-size-log2 19, plain continuations

Peak RAM
before 13.
after 11.0 GB
  • Smaller proofs: unchanged (the write step was never the peak).
  • Wall time: unchanged within noise (marginally faster — avoids allocating and growing a
    multi-GB Vec).

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