Skip to content

perf(proxy): avoid deep header copies in transparent forwarding - #199

Merged
ovaistariq merged 3 commits into
mainfrom
perfloop-pr-open-d1qw355kc5
Sep 3, 2026
Merged

ovaistariq merged 3 commits into
mainfrom
perfloop-pr-open-d1qw355kc5

Conversation

@perfloop

@perfloop perfloop Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Transparent forwarding currently deep-clones every inbound header map and value slice before adding proxy headers. That repeats the full header copy on each uncached S3 operation.

The forwarded request now gets a private shallow header map. Unchanged value slices are reused read-only with their capacity capped, while proxy, date, and content-encoding entries are set on the private map. This keeps client headers intact and prevents generated proxy headers from appearing on the inbound request. Tests cover header ownership, open response bodies, transport errors, forwarding variants, and append isolation.

make lint-ci, make build, make test, make test-integration, make test-race, and make test-coverage pass.

Workload: authenticated transparent passthrough for a small uncached S3 GET with typical AWS SDK headers

Metric Before After Change
ns/op 8872 7559 14.8% lower
B/op 6370 5442 14.6% lower
allocs/op 44 41 6.8% lower
Checks: 6 passed.

Generated by Perfloop. Measurements and checks.


Note

Medium Risk
Request forwarding and header aliasing are subtle; incorrect sharing could leak proxy credentials onto the inbound request or corrupt client headers, though coverage is extensive.

Overview
Transparent forwarding no longer deep-clones every inbound header on each upstream request. buildTransparentRequest now uses shallowHeaderCopy: a private header map for the outbound request while reusing unchanged value slices from the client (with slice capacity capped so appends on the forwarded request cannot mutate the inbound map).

Proxy headers, synthesized X-Amz-Date, and Content-Encoding tweaks still apply only on the forwarded request, so client-visible headers stay unchanged. New unit tests cover borrowing, append isolation, and header privacy across Forward, ForwardWithCapture, DoRequestWithCreds, open response bodies, and transport errors; a benchmark tracks authenticated passthrough setup cost (~15% fewer allocs/time in the PR description).

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

@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown

Greptile Summary

The PR optimizes transparent forwarding by replacing deep header cloning with a private header map that borrows capacity-capped, read-only value slices.

  • Keeps generated proxy, date, and content-encoding headers isolated from the inbound request.
  • Adds ownership, error-path, response-lifetime, and append-isolation tests.
  • Adds a focused benchmark for authenticated uncached S3 forwarding.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete correctness, security, or compatibility failures identified.

The forwarded request receives an independent header map, changed headers receive private value slices, unchanged values remain read-only, and the relevant forwarding and benchmark paths do not mutate shared slices or retain contaminating state.

Important Files Changed

Filename Overview
proxy/forwarder_transparent.go Introduces a private shallow header-map copy with capacity-capped borrowed values; no concrete correctness regression was identified.
proxy/forwarder_transparent_test.go Adds focused coverage for header ownership, append isolation, open response bodies, transport failures, and synchronous forwarding paths.
proxy/forwarder_transparent_benchmark_test.go Adds a controlled authenticated forwarding benchmark without observable cross-iteration state contamination.
proxy/forwarder.go Updates interface documentation to describe the new transparent-forwarding ownership model.

Reviews (1): Last reviewed commit: "perf: borrow unchanged header values for..." | Re-trigger Greptile

@ovaistariq
ovaistariq merged commit 38fc930 into main Sep 3, 2026
11 checks passed
@ovaistariq
ovaistariq deleted the perfloop-pr-open-d1qw355kc5 branch September 3, 2026 00:22
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 3, 2026
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.21.0 🎉

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