Skip to content

Skip destination read-back for null segments during assembly - #368

Merged
folbricht merged 1 commit into
masterfrom
skip-null-segment-readback
Jul 8, 2026
Merged

folbricht merged 1 commit into
masterfrom
skip-null-segment-readback

Conversation

@folbricht

Copy link
Copy Markdown
Owner

Problem

After writing a seed segment, the AssembleFile workers read every chunk of the segment back from the destination and hash it, to catch seeds whose content changed while the extraction was running. This read-back also runs for null segments, where the rationale doesn't apply: a nullChunkSection writes deterministic zeros (or clones from desync's own temporary block file), so there is no external file that can change underneath the extraction. Plan.Validate already treats null segments as always-valid for the same reason.

For sparse files such as VM images, this read-back is essentially the entire cost of assembly: the null writes themselves are nearly free (skipped entirely on blank files, or reflinked), while reading back and SHA512/256-hashing the zeroed ranges runs at only ~500 MB/s per core.

Change

Skip the post-write read-back for null segments, identified by an empty FileName() — the same convention isFileSeed() uses in the sequencer. Read-back still runs for all file seed segments.

Assembling a 1 GiB image that is ~97% zeros (chunked at default sizes, local store, N: 10) went from 1.5 s to under 0.1 s, with the output verified byte-identical.

Also adds a test that assembles a null-heavy index over an existing file full of random data, confirming null sections are still written out correctly without the read-back.

After writing a seed segment, AssembleFile reads every chunk of the segment back from the destination and hashes it to detect seeds that changed while the extraction was running. Null segments were subject to the same read-back even though they have no external source that could change: they write deterministic zeros (or clone from desync's own temporary block file), so there is nothing to re-validate.

For sparse files like VM images this read-back dominates the entire assembly time since SHA512/256 runs at roughly 500 MB/s per core while the null writes themselves are nearly free (skipped entirely on blank files, or reflinked). Skipping the read-back for null segments, identified by an empty FileName like Plan.Validate already does, cuts assembly of a 1 GiB image that is 97% zeros from 1.5s to under 0.1s in local testing.
@folbricht
folbricht force-pushed the skip-null-segment-readback branch from 28f32db to 9ef5e13 Compare July 8, 2026 08:00
@folbricht
folbricht merged commit 15a491d into master Jul 8, 2026
3 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

⌂ 换网址