Skip to content

perf: get_localised_vector with pre-compiled regex - #1038

Open
saquibsaifee wants to merge 1 commit into
CycloneDX:mainfrom
saquibsaifee:perf-optimize-regex-14472361037753830356
Open

perf: get_localised_vector with pre-compiled regex#1038
saquibsaifee wants to merge 1 commit into
CycloneDX:mainfrom
saquibsaifee:perf-optimize-regex-14472361037753830356

Conversation

@saquibsaifee

Copy link
Copy Markdown
Contributor

Description

💡 What:
Optimized get_localised_vector in VulnerabilityScoreSource to use pre-compiled module-level regular expressions instead of calling re.sub() inline.

🎯 Why:
Pre-compiling the regexes (_RE_CVSS_V4, _RE_CVSS_V3, _RE_CVSS_V2, _RE_OWASP) prevents Python from recompiling the pattern or querying its internal regex cache every time get_localised_vector is called.

📊 Measured Improvement:
Measured performance over 100,000 iterations for the regex substitution block:

  • Baseline: 0.7516 seconds
  • Optimized: 0.5333 seconds
  • Improvement: ~30% faster execution time for regex substitution.

AI Tool Disclosure

  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: Gemini Jules
    • LLMs and versions: Gemini 3.1 Pro

Affirmation

@saquibsaifee
saquibsaifee requested a review from a team as a code owner September 1, 2026 21:12
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@read-the-docs-community

read-the-docs-community Bot commented Sep 1, 2026

Copy link
Copy Markdown

Signed-off-by: saquibsaifee <saquibsaifee2@gmail.com>
@saquibsaifee
saquibsaifee force-pushed the perf-optimize-regex-14472361037753830356 branch from d8873bb to f81d6bb Compare September 1, 2026 21:36
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