Skip to content

perf(detector): hoist inline Pattern.compile to static finals (RAN-32)#69

Merged
aksOps merged 1 commit into
mainfrom
perf/ran-32-hoist-pattern-compile
Apr 24, 2026
Merged

perf(detector): hoist inline Pattern.compile to static finals (RAN-32)#69
aksOps merged 1 commit into
mainfrom
perf/ran-32-hoist-pattern-compile

Conversation

@aksOps
Copy link
Copy Markdown
Contributor

@aksOps aksOps commented Apr 24, 2026

Summary

Removes regex recompilation from hot paths in three Java detectors. Each
inline Pattern.compile(...) call inside detect() is replaced with a
reference to a private static final Pattern constant compiled once at
class 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 LdapAuthDetector and 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

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>
@sonarqubecloud
Copy link
Copy Markdown

@aksOps
Copy link
Copy Markdown
Contributor Author

aksOps commented Apr 24, 2026

Code review

No 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 👎.

@aksOps aksOps merged commit 0b47514 into main Apr 24, 2026
8 checks passed
@aksOps aksOps deleted the perf/ran-32-hoist-pattern-compile branch April 26, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant