perf(detector): hoist inline Pattern.compile to static finals (RAN-32)#69
Merged
Conversation
Removes regex recompilation from hot paths in three Java detectors. Each inline Pattern.compile() call inside detect() now references a private static final Pattern compiled once at class load. - ConfigDefDetector: VALUE_KEY_RE, QUOTED_STRING_RE - KafkaDetector: QUOTED_TOPIC_RE - SpringRestDetector: BARE_QUOTED_RE Pure refactor — same regex source, same flags. All 344 affected detector tests pass. Co-Authored-By: Paperclip <noreply@paperclip.ing>
|
Contributor
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
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.



Summary
Removes regex recompilation from hot paths in three Java detectors. Each
inline
Pattern.compile(...)call insidedetect()is replaced with areference to a
private static final Patternconstant compiled once atclass load.
ConfigDefDetector:VALUE_KEY_RE,QUOTED_STRING_RE(was lines 160 & 168)KafkaDetector:QUOTED_TOPIC_RE(was line 87)SpringRestDetector:BARE_QUOTED_RE(was line 345)These detectors run across every Java source file during indexing, so the
inline compiles were a measurable allocation/CPU hit at Code IQ scale.
Pure refactor — same regex source, same flags, no behavioral change.
Reference style follows the existing static-final pattern already used
throughout
LdapAuthDetectorand the rest of the file in each detector.Refs: RAN-32, parent RAN-1, source audit RAN-6.
Test plan
mvn -Dtest='ConfigDefDetectorTest,SpringRestDetectorExtendedTest,JavaDetectorsBranchCoverageTest,JavaDetectorsCoverageTest,JavaDetectorsExtendedTest,JavaDetectorsTest' test→ 344 tests, 0 failures, 0 errors
grep -n "Pattern.compile" <files>confirms no inline compiles remain in detect paths