Skip to content

fileserver: reuse static hide-path list across requests#7848

Open
jvoisin wants to merge 1 commit into
caddyserver:masterfrom
jvoisin:fs2
Open

fileserver: reuse static hide-path list across requests#7848
jvoisin wants to merge 1 commit into
caddyserver:masterfrom
jvoisin:fs2

Conversation

@jvoisin

@jvoisin jvoisin commented Jun 29, 2026

Copy link
Copy Markdown

transformHidePaths rebuilt the hide list on every request, allocating a new []string and re-running ReplaceAll and FastAbs on each entry, even though Provision already resolves static (placeholder-free) hide paths to absolute form ahead of time. file_server is a popular handler I think, and the common case (including the default that hides the Caddyfile) has a fully static hide list, so this is pure per-request garbage. While removing a single allocation isn't much, it's still helping reducing GC work.

Track during provisioning whether every Hide entry is static (no "{"), and when so, return the already-transformed fsrv.Hide directly. Entries containing placeholders still take the per-request resolution path. The returned slice is only read (fileHidden and logging), so sharing it is safe.

Adds a benchmark as per policy, with 3 static hide entries:

TransformHidePaths

  • sec/op 264.2n -> 2.5n (-99.05%)
  • B/op 48 -> 0 (-100%)
  • allocs/op 1 -> 0 (-100%)

Assistance Disclosure

"No AI was used."

transformHidePaths rebuilt the hide list on every request, allocating a
new []string and re-running ReplaceAll and FastAbs on each entry, even
though Provision already resolves static (placeholder-free) hide paths to
absolute form ahead of time. file_server is a popular handler I think,
and the common case (including the default that hides the Caddyfile) has a
fully static hide list, so this is pure per-request garbage.
While removing a single allocation isn't much, it's still helping reducing GC
work.

Track during provisioning whether every Hide entry is static (no "{"), and
when so, return the already-transformed fsrv.Hide directly. Entries
containing placeholders still take the per-request resolution path. The
returned slice is only read (fileHidden and logging), so sharing it is
safe.

Adds a benchmark as per policy, with 3 static hide entries:

TransformHidePaths
- sec/op  264.2n -> 2.5n  (-99.05%)
- B/op 48 -> 0  (-100%)
- allocs/op 1 -> 0  (-100%)
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.

1 participant