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

@dougqh dougqh 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 owner February 18, 2026 19:17
@dougqh dougqh added the type: feature 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
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
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
Copy Markdown
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.

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.Matcher matcher = pattern.matcher(query);
return matcher.replaceAll("<redacted>");
return pattern.matcher(query).replaceAll("<redacted>");

@github-actions

github-actions Bot commented Jul 1, 2026

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-actions github-actions Bot 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

dougqh commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

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

@dougqh dougqh closed this Jul 1, 2026
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 tag: stale Stale pull requests type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants