Skip to content

Use Matcher.replaceAll in QueryObfuscator#10630

Open
dougqh wants to merge 1 commit intomasterfrom
dougqh/query-obfuscator-quick-optimization
Open

Use Matcher.replaceAll in QueryObfuscator#10630
dougqh wants to merge 1 commit intomasterfrom
dougqh/query-obfuscator-quick-optimization

Conversation

@dougqh
Copy link
Contributor

@dougqh dougqh commented Feb 18, 2026

What Does This Do

Changes QueryObfuscator to use Matcher.replaceAll to perform redaction
Improves worst case performance of QueryObfuscator at the expense of average case performance

Motivation

In the QueryObfuscatorBenchmark, the no redact & simple redact cases drop-off by 4-6%, but the large redact case improves 3x.

Additional Notes

In subsequent PR, I'm going to use regex matching on CharSequence that provide a view into the query string to further reduce the overhead. This PR is just a stop gap to mitigate the worst case behavior.

Contributor Checklist

Jira ticket: [PROJ-IDENT]

Note: Once your PR is ready to merge, add it to the merge queue by commenting /merge. /merge -c cancels the queue request. /merge -f --reason "reason" skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.

Improves worst case performance of QueryObfuscator at the expense of average case performance

In the QueryObfuscatorBenchmark, the no redact & simple redact cases drop-off by 4-6%, but the large redact improves 3x.
@dougqh dougqh requested a review from a team as a code owner February 18, 2026 19:17
@dougqh dougqh added the type: enhancement Enhancements and improvements label Feb 18, 2026
@dougqh dougqh requested a review from mhlidd February 18, 2026 19:17
@dougqh dougqh added tag: performance Performance related changes comp: asm waf Application Security Management (WAF) labels Feb 18, 2026
@dougqh dougqh changed the title Use Matcher.replaceAll Use Matcher.replaceAll in QueryObfuscator Feb 18, 2026
Comment on lines +52 to +53
java.util.regex.Matcher matcher = pattern.matcher(query);
return matcher.replaceAll("<redacted>");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Nice, but how about to put a comment here that we are using JUL matcher, not Google one for performance reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was actually a mistake, my IDE didn't pick up RE2 and auto-completed the wrong thing. Now, I need to double check everything. Ugh, that's what I get for rushing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might just scrap this PR, since I now have a better solution nearly ready to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: asm waf Application Security Management (WAF) tag: performance Performance related changes type: enhancement Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments