fileserver: reuse static hide-path list across requests#7848
Open
jvoisin wants to merge 1 commit into
Open
Conversation
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%)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Assistance Disclosure
"No AI was used."