Skip to content

Use Matcher.replaceAll in QueryObfuscator - #10630

Closed
dougqh wants to merge 1 commit into
masterfrom
dougqh/query-obfuscator-quick-optimization
Closed

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

Conversation

@dougqh

@dougqhdougqh commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

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 ownerFebruary 18, 2026 19:17
@dougqhdougqh added the type: feature Enhancements and improvements label Feb 18, 2026
@dougqh
dougqh requested a review from mhliddFebruary 18, 2026 19:17
@dougqhdougqh added tag: performance Performance related changes comp: asm waf Application Security Management (WAF) labels Feb 18, 2026
@dougqhdougqh changed the title Use Matcher.replaceAllUse Matcher.replaceAll in QueryObfuscatorFeb 18, 2026
Comment on lines +52 to +53
java.util.regex.Matcher matcher = pattern.matcher(query);
return matcher.replaceAll("<redacted>");

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be

Suggested change
java.util.regex.Matchermatcher = pattern.matcher(query);
returnmatcher.replaceAll("<redacted>");
returnpattern.matcher(query).replaceAll("<redacted>");

@bm1549
bm1549 removed the request for review from mhliddMarch 20, 2026 18:37
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale because it has not had activity over the past quarter. It will be closed in 7 days if no further activity occurs. Feel free to reopen the PR if you are still working on it.

@github-actionsgithub-actionsBot added the tag: stale Stale pull requests label Jul 1, 2026
@bric3

bric3 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

THis pr don;t compile, also there's now this PR #11649

@dougqh

Copy link
Copy Markdown
ContributorAuthor

Yes, I've basically abandoned this one. I'm just going to close it.

@dougqhdougqh closed this Jul 1, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: asm wafApplication Security Management (WAF)tag: performancePerformance related changestag: staleStale pull requeststype: featureEnhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@dougqh@bric3@AlexeyKuznetsov-DD