REGEX_PATTERNS static in secrets_redactor.rs increased the P50 memory usage#330
Closed
ZhidongPeng wants to merge 6 commits intoAzure:devfrom
Closed
REGEX_PATTERNS static in secrets_redactor.rs increased the P50 memory usage#330ZhidongPeng wants to merge 6 commits intoAzure:devfrom
ZhidongPeng wants to merge 6 commits intoAzure:devfrom
Conversation
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.
Issue:
REGEX_PATTERNS static in secrets_redactor.rs (PR #317)
The regex crate compiles each pattern to an NFA and pre-builds DFA transition tables. For complex patterns with deep alternation and lookaheads, this can easily consume hundreds of KB each. 17 patterns × ~200–400 KB each = estimated 3–5 MB permanently resident.
Fix:
Part 1 — Eliminate 6 compiled Regex objects entirely
The patterns pwd=[^;], password=[^;], AccountKey=[^;], PrimaryKey=[^;], SecondaryKey=[^;], and sig=[^&] are all structurally identical: match a fixed literal prefix, then capture everything up to a single stop character. The new redact_prefixed() helper does this with plain str::find — zero compiled automaton, zero regex heap.
Memory saved: ~6 compiled Regex objects removed (the simple ones each cost tens of KB; gone completely).
Part 2 — Per-indicator LazyLock dispatch for the 11 complex patterns
Previously: any indicator (e.g., the word "key" in a path like "key_keeper") triggered all 17 patterns to run.
Now: each pattern has its own static LazyLock and only runs when its own specific indicator is present.