Skip to content

storage: reduce manifest verification latency - #4906

Merged
milosgajdos merged 1 commit into
distribution:mainfrom
perfloop-oss:perfloop-pr-open-2s4z8mcfgb
Nov 11, 2026
Merged

milosgajdos merged 1 commit into
distribution:mainfrom
perfloop-oss:perfloop-pr-open-2s4z8mcfgb

Conversation

@perfloop-agent

@perfloop-agent perfloop-agent commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Reduce Manifest Verification Latency

Headline Win

  • verifyManifest_latency (Primary Win): baseline 128,746,104 ns/op -> candidate 21,460,250.5 ns/op, -83.3313% reduction (n=10, p-value = 1.08251e-05, significant), validated/won. No behavior change.
  • verifyManifest_oci_latency (Improved Guardrail / Held Guardrail): baseline 128,014,403 ns/op -> candidate 21,378,921 ns/op, -83.2996% reduction (n=10, p-value = 1.08251e-05, significant), outcome held as a guardrail.

These figures are measured against a synthetic storage driver injecting 10ms of latency per operation to model a remote object-storage backend (detailed under "Performance Comparison" below). The mechanism is a sum-to-max transformation of independent I/O-bound checks, so the absolute reduction scales with per-check backend latency and the number of manifest references; a fast local backend sees a proportionally smaller gain.


Why It Matters

The verifyManifest method validates each descriptor referenced by a manifest (including both Schema 2 and OCI manifest handlers) in a sequential loop. It performs independent, I/O-bound storage existence checks (using manifestService.Exists and blobsService.Stat) for each layer or manifest.

Step Independence Proof from Source Code

An inspection of the source code confirms that the individual descriptor existence checks are completely independent:

  • The verification loop iterates over a pre-extracted array/slice of references obtained via mnfst.References().
  • All input descriptors and their digests are fully available in memory before the verification loop begins.
  • None of the verification steps consumes or depends on the output of any other step.

Because these checks are completely independent and block on downstream storage I/O, serial execution causes the total verification latency to scale linearly with the number of references ($O(N) \times \text{latency of a single check}$). By overlapping these checks, we reduce latency from the sum of the check durations to the maximum of those durations, significantly improving manifest put performance.


Error Handling Semantics

Error-handling semantics are preserved. Each goroutine collects its descriptor's validation/existence errors into a per-index slot of a preallocated slice and always returns nil to the errgroup, so no check's failure cancels the group: every reference is checked to completion, and all errors are aggregated in the original reference order and returned together, exactly as the sequential loop did. The group context ends only when the caller's context does. The behavioral difference is concurrency itself: up to DefaultManifestVerificationConcurrencyLimit existence checks run against the storage driver at once, where the sequential loop issued one at a time.


Reproduction Recipe

Environment

  • OS: linux
  • Arch: amd64
  • Runtime: go1.26.4

Commits

  • Baseline Commit: 472c9d38c9fc523599f37ca3207279e5ab10f74f
  • Candidate Commit: f22306aa031576335b75b6a8d396003cdb2fd2c2

Verification Benchmarks

The benchmarks used to measure performance were newly authored by the agent to ensure clean, cache-independent testing. To reproduce these results using standard Go tools, run the following benchmark commands:

  1. Docker Schema 2 Manifest Verification Benchmark:

    go test -bench='^BenchmarkSchema2ManifestVerify$' -run='^$' -count=1 ./registry/storage
  2. OCI Manifest Verification Benchmark:

    go test -bench='^BenchmarkOCIManifestVerify$' -run='^$' -count=1 ./registry/storage

Performance Comparison

Metric / Selector Baseline (ns/op) Candidate (ns/op) Delta (%) Outcome
verifyManifest_latency 128,746,104 21,460,250.5 -83.3313% Validated / Won (Primary)
verifyManifest_oci_latency 128,014,403 21,378,921 -83.2996% Outcome held as a guardrail

The candidate latency of ~21ms is mathematically double the simulated 10ms driver latency because the manifestService.Put operation consists of two sequential phases:

  1. verifyManifest executes all descriptor presence checks in parallel (taking $\max(10\text{ms}) = 10\text{ms}$).
  2. The manifest itself is written to the blob store using ms.blobStore.Put, which incurs an additional sequential 10ms driver Stat check.
    This validates the sum-to-max transformation.

Correctness & Quality Gates

All of the following correctness checks passed successfully (and no other suites were claimed):

  • pairing
  • environment_consistent
  • baseline_valid
  • benchmark_passed
  • Build Check (using command go build ./registry/storage/...)
  • Concurrency & Race Check (using command go test -race -v ./registry/storage/... -run "TestVerifyManifest")
  • Format Check (using command go fmt ./registry/storage/...)
  • measurements_sane
  • metric_present
  • sample_sufficiency
  • sample_independence

The Change

We implemented race-free parallel manifest verification for both Docker Schema 2 and OCI manifest handlers:

  1. Parallel Reference Checks: Updated the verifyManifest method in both schema2ManifestHandler (registry/storage/schema2manifesthandler.go) and ocischemaManifestHandler (registry/storage/ocimanifesthandler.go) to process referenced descriptors concurrently using golang.org/x/sync/errgroup.
  2. Bounded Concurrency: Added a new package-level constant DefaultManifestVerificationConcurrencyLimit = 16 in registry/storage/registry.go to decouple verification concurrency from GOMAXPROCS, preventing downstream network/storage resource exhaustion.
  3. Deterministic Error Ordering (With Context Limits): Errors from each goroutine are written into a preallocated indexed slice to preserve ordering, subject to the fail-fast cancellation described above.

Touched Files

  • registry/storage/registry.go
  • registry/storage/schema2manifesthandler.go
  • registry/storage/ocimanifesthandler.go
  • registry/storage/ocimanifesthandler_benchmark_test.go (newly added OCI verification benchmark)

Tried and Ruled Out (Alternatives)

  • cand_dftjcmdstj (commit 615209bab6fbf7d244f240faa955a6d3bc308bce): This candidate was inconclusive because its ns/op samples were byte-identical across all 10 baseline/candidate runs due to Go test caching (the verifier failed sample_independence checks). This candidate successfully parallelized the loops using errgroup.WithContext, but lacked cache-independent bench testing.

Limits & Real-World Validation Target

  • Scope: Manifest verification was benchmarked under simulated 10ms driver latency with 10 referenced layers on memory-backed storage drivers.
  • Real-World Proof Target: To prove this behavior under production conditions, the target is production trace spans showing sequential execution versus overlapping execution with their summed and maximum durations.
  • Confidence Qualification: Our confidence is qualified as medium, as real-world networks/backends will introduce variable latency, socket contention, and different concurrent overlapping behaviors.

Full Proof

The complete performance proof is available at:
https://app.perfloop.ai/t/oss/case_zptzacr9b7


This is an automated, human-reviewed Perfloop contribution opened by perfloop-agent. The body links to reproducible proof for the change. The change was benchmarked on perfloop/distribution, an automation fork of distribution/distribution; the commit on this PR's head branch carries the proof.

Assisted-by: PerfloopAgent:gemini-3.5-flash

@perfloop-agent
perfloop-agent force-pushed the perfloop-pr-open-2s4z8mcfgb branch from adcdd26 to 4d4b624 Compare July 9, 2026 16:23
@tsenart

tsenart commented Nov 10, 2026

Copy link
Copy Markdown

@milosgajdos thanks for approving this back in July. Is there anything else you need from me to get it merged?

@milosgajdos
milosgajdos merged commit ae19f09 into distribution:main Nov 11, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants