Skip to content

perf(cache-proxy): seek to range start instead of discard-reading block prefix - #1042

Merged
EDsCODE merged 1 commit into
mainfrom
eric/cache-proxy-seek-block-prefix
Aug 9, 2026
Merged

perf(cache-proxy): seek to range start instead of discard-reading block prefix#1042
EDsCODE merged 1 commit into
mainfrom
eric/cache-proxy-seek-block-prefix

Conversation

@EDsCODE

@EDsCODE EDsCODE commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

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.openFile and 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=1 green; -race green for the block-aligned/drifted/concurrent tests.
  • Existing drifted-range warm-hit tests assert body content for mid-block slices, which is exactly the behavior this touches.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

Test Impact Plan

Deterministic summary of how this PR changes tests, CI runners, and coverage-risk signals.

Summary

Area Added Changed Deleted
Test files 0 0 0
E2E/journey files 0 0 0
Workflow files 0 0 0

Signals

  • Test cases: +0 / -0
  • Assertions: +0 / -0
  • Skips or known failures added: 0
  • Workflow continue-on-error added: 0
  • Workflow path filters added: 0
  • Test commands removed from justfile: 0
  • E2E/journey retry lines added: 0

Coverage risk: neutral or increased

No coverage-reduction warnings detected.

@EDsCODE
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
EDsCODE force-pushed the eric/cache-proxy-seek-block-prefix branch from ec2ce27 to 5a63bbb Compare August 9, 2026 19:21
@EDsCODE
EDsCODE merged commit 3e71c91 into main Aug 9, 2026
31 checks passed
@EDsCODE
EDsCODE deleted the eric/cache-proxy-seek-block-prefix branch August 9, 2026 19:44
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