Skip to content

perf: avoid copying already rooted request paths - #2794

Open
andreybolonin wants to merge 1 commit into
php:mainfrom
andreybolonin:perf/avoid-rooted-path-copy
Open

andreybolonin wants to merge 1 commit into
php:mainfrom
andreybolonin:perf/avoid-rooted-path-copy

Conversation

@andreybolonin

Copy link
Copy Markdown
Contributor

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. Benchmarks were not rerun for this PR.

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 553,791 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.

This branch has not been deployed

No deployments
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