Skip to content

perf: use byte search to split response headers - #2796

Merged
dunglas merged 2 commits into
php:mainfrom
andreybolonin:perf/vectorize-response-header-scan
Nov 1, 2026
Merged

dunglas merged 2 commits into
php:mainfrom
andreybolonin:perf/vectorize-response-header-scan

Conversation

@andreybolonin

Copy link
Copy Markdown
Contributor

Response header splitting scans for : one byte at a time. Use bytes.IndexByte to find the same first separator while keeping the existing key/value copies and space-only trimming.

Add table tests, a differential fuzz test, and a direct splitting benchmark, including missing separators, embedded NUL bytes, tabs, and additional colons.

Initial standalone measurements (Go 1.27.3, Apple M2, darwin/arm64, one 150ms sample per case):

Header Before After Time reduction Go B/op allocs/op
X-Request-Id 24.44 ns 20.31 ns 16.9% 32 → 32 2 → 2
Access-Control-Allow-Credentials 35.68 ns 22.99 ns 35.6% 36 → 36 2 → 2
Content-Type 25.42 ns 24.33 ns 4.3% 32 → 32 2 → 2

These exploratory helper measurements are not a statistical comparison or a whole-request speedup claim. Benchmarks were not rerun for this PR.

Validation: gofmt and git diff --check passed. The exact CGO helper and its added tests passed with -race in an isolated harness; differential fuzzing passed 631,569 executions, and go vet passed. Full FrankenPHP tests were not run locally because the required PHP ZTS/shared-library and watcher setup is unavailable.

@dunglas
dunglas merged commit 7569e89 into php:main Nov 1, 2026
28 checks passed
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.

2 participants