Skip to content

perf(storage): bound resolveByProviderId fan-out with an ordered sliding window#853

Open
SgtPooki wants to merge 8 commits into
masterfrom
fix/resolve-by-provider-id-pqueue
Open

perf(storage): bound resolveByProviderId fan-out with an ordered sliding window#853
SgtPooki wants to merge 8 commits into
masterfrom
fix/resolve-by-provider-id-pqueue

Conversation

@SgtPooki

@SgtPooki SgtPooki commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What changed

resolveByProviderId evaluates a provider's data sets oldest-first through a sliding read pool: at most RESOLVE_CONCURRENCY (10) reads in flight, topping up the instant one finishes. It reads metadata first and getActivePieceCount only on a metadata match, and never starts a data set newer than the oldest non-empty match it has already found. So the read fan-out shrinks to roughly the match position instead of reading every candidate.

This replaces the fixed 50-200 batch, which read every candidate before inspecting any result and stalled at batch boundaries for clients with many data sets per provider.

The pool is a bounded Set + Promise.race that tops up as each read settles (the same sliding-window shape rvagg asked for, and the one already used in apps/backend/.../ipfs-block.strategy.ts on the dealbot side). No new dependency.

How to verify

Selection is unchanged: oldest non-empty metadata match, else oldest metadata match, else null. Tests in storage.test.ts: bounded fan-out for a 196-data-set provider, oldest-non-empty selection across the window, and oldest-of-several-non-empty with the newer match never read.

Refs #631.

…ing window

Evaluate a provider's candidate data sets oldest-first with at most
RESOLVE_CONCURRENCY reads in flight, reading metadata before activePieceCount
and stopping once the oldest non-empty metadata match is known. Selection is
unchanged: oldest non-empty metadata match, else oldest metadata match, else
null.

Refs #631
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Jun 17, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 17, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
synapse-dev bbb1907 Commit Preview URL

Branch Preview URL
Jun 24 2026, 06:41 PM

@BigLep BigLep moved this from 📌 Triage to 🔎 Awaiting review in FOC Jun 18, 2026
Clear the PQueue in a finally so a rejected metadata/piece-count read stops
issuing the remaining reads instead of running the fan-out resolveByProviderId
is meant to bound. In-flight reads (<= RESOLVE_CONCURRENCY) run to completion.

Add a test pinning oldest-of-several-non-empty selection plus the early-exit
guard: the newer non-empty match's getActivePieceCount is never read once the
oldest is known.

This comment was marked as outdated.

SgtPooki added 2 commits June 18, 2026 16:01
Replace the enqueue-one-PQueue-task-per-dataset approach with a bounded
sliding pool (Set + Promise.race, topping up as each read finishes). The pool
never starts datasets newer than the oldest non-empty match it has found, so
the read fan-out shrinks to roughly the match position instead of allocating
and draining a no-op task per dataset. This makes it a real sliding window and
drops the p-queue dependency.

Export RESOLVE_CONCURRENCY so the fan-out test derives its bound from it.
Resolve conflict in storage/context.ts: keep the ordered sliding-window
resolveByProviderId fan-out from this branch, but adopt master's cheaper
hasActivePieces() boolean check (PR #852) in place of getActivePieceCount().
Update the resolve-window tests to mock getActivePieces accordingly.

Claude-Session: https://claude.ai/code/session_01HFNuoASCSpUJWSu8XZRjfd

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread packages/synapse-sdk/src/storage/context.ts Outdated
Comment thread packages/synapse-sdk/src/test/storage.test.ts Outdated
Comment thread packages/synapse-sdk/src/test/storage.test.ts

@BravoNatalie BravoNatalie left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks solid and clean!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting review

Development

Successfully merging this pull request may close these issues.

4 participants