Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 07:15 UTC
caddyhttp: allocate the request UUID lazily instead of on every request (#7936)
addHTTPVarsToReplacer ran SetVar(ctx, "uuid", new(requestID)) for every request during replacer setup, allocating a *requestID unconditionally even though it is only ever read by the {http.request.uuid} placeholder. The UUID value itself was already generated lazily (requestID.String caches on first call), but the container was not. Allocate the *requestID on first access instead: the uuid placeholder now creates and stores it in the request's vars table when absent, so repeated references within a request still share one instance (and thus one UUID), while requests that never reference the UUID pay nothing. Add a benchmark for the per-request replacer setup and a regression test for the uuid placeholder, which previously had no coverage. Benchmark (BenchmarkAddHTTPVarsToReplacer, linux/arm64, count=6), common path where the UUID is never referenced: before: ~700 ns/op 352 B/op 9 allocs/op after: ~690 ns/op 336 B/op 8 allocs/op One 16-byte allocation removed per request; a GC-pressure win rather than a latency one.