Skip to content

perf(backup-helper): compute prepare CommP across a worker_threads pool - #8

Merged
BravoNatalie merged 2 commits into
mainfrom
review/tippyflitsuk-parallel-prepare
Jun 5, 2026
Merged

perf(backup-helper): compute prepare CommP across a worker_threads pool#8
BravoNatalie merged 2 commits into
mainfrom
review/tippyflitsuk-parallel-prepare

Conversation

@BravoNatalie

@BravoNatalie BravoNatalie commented Jun 5, 2026

Copy link
Copy Markdown
Owner

work cherry-picked from @TippyFlitsUK PR #7 (commit 1de3e21)

prepare — parallel CommP hashing (perf)

prepare computes a piece CID for every shard missing one, via the pure-JS @filoz/synapse-core/piece hash. That hash is CPU-bound and single-threaded, so on a multi-core node prepare pins one core and leaves the rest idle.

This moves the hashing into a worker_threads pool sized to --concurrency. Each worker calls the same calculateFromIterable, so output piece CIDs are byte-identical to the single-thread path — only throughput changes. DB writes and shard→piece renames stay on the main thread (sqlite isn't shared with workers).

Measured on a 64-core machine, single dataset (~10 MB average CARs):

--concurrency throughput
8 ~20 MB/s
24 ~69 MB/s
32 ~84 MB/s

Knee around 32 on that box (the per-core JS hash is the ceiling); scales with available cores. Piece-CID output verified

TippyFlits and others added 2 commits June 5, 2026 02:06
prepare computes a piece CID for every shard missing one via the pure-JS
@filoz/synapse-core/piece hash. That hash is CPU-bound and single-threaded,
so on a multi-core node prepare pins one core and leaves the rest idle.

Move the hashing into a worker_threads pool sized to --concurrency. Each
worker calls the same calculateFromIterable, so output piece CIDs are
byte-identical to the single-thread path; only throughput changes. DB
writes and shard->piece renames stay on the main thread (sqlite is not
shared with workers).

Measured on a 64-core machine (~10 MB avg CARs): ~20 MB/s at -c 8,
~69 MB/s at -c 24, ~84 MB/s at -c 32 (knee ~32 on that box). No change to
default concurrency or any existing flag.

(cherry picked from commit 1de3e21)
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