Skip to content

perf: remove cache range pipe relay - #215

Merged
ovaistariq merged 2 commits into
mainfrom
perfloop-pr-open-1a34ftfbjy
Oct 21, 2026
Merged

ovaistariq merged 2 commits into
mainfrom
perfloop-pr-open-1a34ftfbjy

Conversation

@perfloop

@perfloop perfloop Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Remove the cache-range pipe relay for cached single-range GETs.

serveRangeFromCache now writes cache chunks directly to the existing lazy response writer. It sends the 206 headers and X-Cache: HIT only when the first non-empty chunk arrives, so empty reads and failures before the first byte remain uncommitted for upstream fallback. After commitment, a stream error keeps the partial response and does not append an upstream response. The cache read continues to use the metadata body's discriminator for versioned entries.

The change keeps range parsing, 206 headers, byte accounting, revalidation, and fallback behavior. Focused tests cover empty reads, failures before and after a strict partial first write, normal-handler fallback, and revalidation callers.

The benchmark enters the transparent-mode production router, warms a non-block cache entry, validates the complete 206 response, and measures 1 KiB, 64 KiB, 1 MiB, and 4 MiB hits.

Tests:

  • go test ./proxy -run '^(TestServeRangeFromCache_EmptyBodyReportsGone|TestServeRangeFromCache_ErrorBeforeFirstByte|TestServeRangeFromCache_ErrorAfterFirstByteKeepsCommittedResponse|TestHandleGetObject_RangeCacheHitPostCommitErrorDoesNotFallBack|TestHandleGetObject_EmptyRangeCacheHitFallsBackBeforeHeaders|TestRevalidationRange304_ServesCachedRange|TestRevalidationRange304_BodyEvictedForwardsUpstream)$' -count=1
  • make lint-ci
  • make build
  • make test
  • make test-integration
  • make test-race
  • make test-coverage

Workload: warm non-block single-range cache hit through the transparent-mode production router, 1 KiB response

Metric Before After Change
cpu-ns/op 59995 17982 70% lower
ns/op 32755 15046 54.1% lower

Workload: warm non-block single-range cache hit through the transparent-mode production router, 64 KiB response

Metric Before After Change
cpu-ns/op 152744 57485 62.4% lower
ns/op 91852 51395 44% lower

Workload: warm non-block single-range cache hit through the transparent-mode production router, 1 MiB response

Metric Before After Change
cpu-ns/op 1475208 533320 63.8% lower
ns/op 976051 477385 51.1% lower

Workload: warm non-block single-range cache hit through the transparent-mode production router, 4 MiB response

Metric Before After Change
cpu-ns/op 6143768 1981245 67.8% lower
ns/op 4433909 1612652 63.6% lower
Checks: 7 passed.

Generated by Perfloop. Measurements and checks.


Note

Medium Risk
Changes hot-path GET/range cache serving and HTTP commit/fallback semantics; behavior is heavily tested but mistakes could affect partial responses or upstream fallback.

Overview
Removes the io.Pipe relay for single-range cache hits and streams range bytes straight to the client via an extended lazyCommitWriter.

serveRangeFromCache now pipes GetRangeStream into that writer, which emits 206, range headers, and X-Cache: HIT only after the first non-empty chunk—so empty or pre-commit failures stay uncommitted and HandleGetObject can still fall back upstream. Post-commit stream errors keep the partial 206 and do not trigger upstream. lazyCommitWriter.Write also surfaces io.ErrShortWrite on incomplete writes.

Adds router-level benchmarks (BenchmarkServeRangeFromCache at 1K–4M) and tests for range stream errors, empty-body fallback, and post-commit behavior. Revalidation comments are updated to match the shared lazy-commit contract.

Reviewed by Cursor Bugbot for commit b6790d0. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no new correctness, compatibility, security, or repository-rule issues were identified.

Summary

  • Commits the 206 Partial Content response and X-Cache: HIT only after the first non-empty cache write.
  • Preserves upstream fallback before commitment and prevents fallback after a partial response has begun.
  • Retains version-discriminated body reads, response headers, byte accounting, and revalidation behavior.
  • Adds focused stream-failure tests and an end-to-end production-router benchmark for several range sizes.

Reviews (2) · Last reviewed commit: "perf: remove range cache pipe relay"

@perfloop
perfloop Bot force-pushed the perfloop-pr-open-1a34ftfbjy branch from a005731 to b6790d0 Compare September 12, 2026 07:42
@ovaistariq
ovaistariq merged commit 4221da6 into main Oct 21, 2026
11 checks passed
@ovaistariq
ovaistariq deleted the perfloop-pr-open-1a34ftfbjy branch October 21, 2026 05:42
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 21, 2026
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.22.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants