perf(cache-proxy): seek to range start instead of discard-reading block prefix - #1042
Merged
Conversation
Test Impact PlanDeterministic summary of how this PR changes tests, CI runners, and coverage-risk signals. Summary
Signals
Coverage risk: neutral or increased No coverage-reduction warnings detected. |
EDsCODE
marked this pull request as ready for review
August 8, 2026 00:07
…ck prefix Serving a range that starts mid-block read the block file from byte zero and discarded the prefix, costing up to a full block of disk reads and copies per request. Block readers are plain files, so seek directly to the slice; the discard path remains as a fallback for non-seekable readers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
EDsCODE
force-pushed
the
eric/cache-proxy-seek-block-prefix
branch
from
August 9, 2026 19:21
ec2ce27 to
5a63bbb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In block-aligned mode, serving a range that starts mid-block opens the block file and then
io.CopyN(io.Discard, ...)s its way to the slice start — reading and copying up to a full block of unwanted prefix per request. Requests almost never start on a block boundary, so a lazy scan issuing thousands of small reads pays this on nearly every one. At 8MiB blocks that's ~half a block (~4MiB) of wasted disk/page-cache reads per request, several seconds per scan, sitting on the serving path.Benchmarks against a production table are consistent with the cost: shrinking blocks 8MiB→1MiB (which shrinks the average discard 8×) moved the fully-warm scan floor from ~6.2s to a stable ~5.3s. Seeking captures that win at any block size.
Change
Block readers come from
DiskCache.openFileand are plain*os.Files, so seek to the slice start instead of discard-reading the prefix. The discard path stays as a fallback for any non-seekable reader. Response bytes are unchanged.Testing
go test ./cmd/cache-proxy -count=1green;-racegreen for the block-aligned/drifted/concurrent tests.🤖 Generated with Claude Code