Repository navigation
Commit d82fc4f
authored
perf: avoid copying already rooted request paths (#2794)
Preparing SCRIPT_FILENAME currently prepends `/` even when the request
path already starts with it. The resulting extra slash makes
`path.Clean` rebuild an otherwise clean path.
Only prepend `/` for unrooted paths. Keep path cleaning, the Windows
locality check, and trailing-slash handling. Add cases for repeated
leading slashes and traversal, plus a benchmark for rooted, relative,
and traversal paths.
Earlier standalone measurements of this helper (Go 1.27.3, darwin/arm64,
median of five 200ms samples):
| Path | Before | After | Time reduction | Go B/op | allocs/op |
| --- | ---: | ---: | ---: | ---: | ---: |
| `/index.php` | 111.8 ns | 69.69 ns | 37.7% | 80 → 32 | 4 → 1 |
| `/products/catalog/index.php` | 153.9 ns | 110.9 ns | 27.9% | 144 → 48
| 4 → 1 |
| Long rooted path | 499.2 ns | 413.3 ns | 17.2% | 656 → 176 | 4 → 1 |
These are helper-level results, not whole-request or RSS measurements.
Relative paths had a 2.4% time reduction with unchanged allocations;
traversal paths had an 11.0% reduction with Go B/op dropping from 96 to
72. The original benchmark cases were not rerun.
Validation:
- `gofmt` and `git diff --check` passed.
- The exact helper and its repository path tests passed with `-race` in
an isolated harness without PHP linkage.
- A differential fuzz run against the original helper passed 657,119
executions.
- The isolated tests cross-compiled for Windows; Windows runtime tests
were not run locally.
- Full FrankenPHP tests were not run: the local environment lacks the
required PHP ZTS/shared-library and watcher setup.
Adversarial benchmark cases use 4096 leading slashes and 512 rooted
`a/../` segments. Separate exploratory measurements (Go 1.27.3, Apple
M2, darwin/arm64; one 300ms sample per case):
| Input | Before | After | Go B/op | allocs/op |
| --- | ---: | ---: | ---: | ---: |
| 4096 leading slashes | 3260 ns | 2782 ns | 9776 → 4912 | 4 → 3 |
| 512 rooted `a/../` segments | 3533 ns | 3391 ns | 5424 → 2736 | 4 → 3
|
These exploratory measurements do not establish statistical significance
or an improvement on every input. Allocation counts and bytes do not
increase in these cases.
The branch also restores the `os` import needed by
`os.ErrDeadlineExceeded`, which was lost when main was merged and caused
the CI compilation failure.1 parent 6dd16e2 commit d82fc4f
2 files changed
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| |||
0 commit comments