[Repo Assist] eng(sanitize): promote inline regexp to package-level var; add SanitizeString benchmark#2328
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
…zeString benchmark SanitizeString calls ReplaceAllStringFunc for every one of the 10 SecretPatterns. When a match contains '=' or ':', the previous code compiled a new regexp inside the closure: parts := regexp.MustCompile(`[=:]\s*`).Split(match, 2) This compiled a fresh *regexp.Regexp on every such match, allocating a new object and re-running the compilation pipeline each time. Moving the pattern to a package-level var (keyValueSplitPattern) compiles it exactly once at init. Also adds BenchmarkSanitizeString (no_secrets / with_secret sub-benchmarks) to make the hot-path cost visible and guard against future regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
15 tasks
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.
🤖 This is an automated PR from Repo Assist.
Summary
Two small engineering improvements to the sanitize package:
1. Promote inline
regexp.MustCompileto package-level varSanitizeStringis called on every log message in the gateway. For each of the 10SecretPatterns, it callsReplaceAllStringFunc. When a match contained=or:, the previous code compiled a brand-new*regexp.Regexpinside the closure:This allocated a new regexp object and re-ran the compilation pipeline on every such match. The fix promotes it to a package-level
var keyValueSplitPattern, compiled exactly once at init:2. Add
BenchmarkSanitizeStringAdds two sub-benchmarks (
no_secrets,with_secret) to make the cost ofSanitizeStringvisible and guard against future regressions.Test Status
TestSanitizeString*tests unchanged.BenchmarkSanitizeStringbenchmark added.proxy.golang.orgis firewalled. CI will validate.Warning
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.