Skip to content

perf: skip unneeded passthrough request body buffers - #212

Closed
PekingSpades wants to merge 1 commit into
httptoolkit:mainfrom
PekingSpades:perf/passthrough-request-buffering
Closed

PekingSpades wants to merge 1 commit into
httptoolkit:mainfrom
PekingSpades:perf/passthrough-request-buffering

Conversation

@PekingSpades

Copy link
Copy Markdown

Ordinary passthrough currently starts a replay buffer even when recording and all body consumers are disabled. Stream those uploads directly, and keep replay buffering for recording, subscriptions, callbacks, transforms and readers started by earlier matchers or steps.

Fixes #211.

Complete reproduction: #211. Based on v4.6.3 (10e33d5).

Changes

  • Pass existing recording/subscription requirements to request steps.
  • Select direct streaming only when no body consumer needs buffering.
  • Keep an existing replay stream when a matcher has already consumed bytes.
  • Add coverage for HTTP/1, HTTP/2, trailers, cancellation, callbacks, transforms, subscriptions and oversized observed uploads.

Actual before/after comparison

The report's loopback reproduction uploads 16 MiB with recordTraffic: false, consumes it at the target, and holds the target response open while measuring.

Measurement Published 4.6.3 / unmodified source This branch
Target received bytes 16,777,216 16,777,216
SHA-256 matches sent content true true
Retained request chunks 16,777,216 bytes 0 bytes
New integration regressions 9 passing, 2 failing 11 passing

The two failing baseline regressions are the unobserved HTTP/1 and HTTP/2 uploads. The other nine compatibility cases pass on both versions. The byte counter measures the request reader's retained chunks, not whole-process memory.

Using the script from the report and a built checkout at ../mockttp:

node request-buffering.cjs
node request-buffering.cjs ../mockttp

Validation

  • npm run build: passed.
  • Browser suite: 340 passing.
  • Full Node suite: 835 passing, 6 pending, 2 failing.
  • Unmodified baseline full Node suite: 823 passing, 6 pending, 3 failing.

The remaining failures were existing live TLS passthrough cases: skips the server for matching HTTPS requests and bypasses Mockttp for TLS connections inside matching HTTP/1 CONNECT tunnel. Both also failed on the unmodified baseline (disconnect/timeout).

All validation used Node 24.19.0, with freshly installed upstream dependencies. Browser checks used Chrome Headless 151.0.7922.34. The full Node suite used a local pkimetal service and a 30-second Mocha timeout. Existing live-network outcomes vary between runs; the deterministic regression and loopback comparisons isolate these changes.

Stream unobserved uploads directly while retaining replay buffers for
recording, subscriptions, callbacks, transforms and earlier readers.
Keep forwarding, trailers and cancellation intact for streamed bodies.
@CLAassistant

CLAassistant commented Sep 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@pimterry pimterry closed this Sep 15, 2026
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.

Passthrough requests retain full bodies with recording and body observers disabled

3 participants