Skip to content

⚡ Bolt: Optimize security scanner array lookups - #423

Open
giauphan wants to merge 2 commits into
mainfrom
bolt-optimize-security-scanner-7520642348003200771
Open

giauphan wants to merge 2 commits into
mainfrom
bolt-optimize-security-scanner-7520642348003200771

Conversation

@giauphan

Copy link
Copy Markdown
Owner

💡 What:
Optimized the SecurityScanner by hoisting static configuration arrays (unsafeFuncs, dbKeywords, nonSecretSubstrings) to the module scope and converting them into Sets where possible to replace O(N) .includes() lookups with O(1) .has() checks. Replaced repetitive .includes() string checks with a single compiled RegExp.

🎯 Why:
The SecurityScanner operates within a hot loop, evaluating every node, link, and word in the AST graph. Previously, these configuration arrays were re-initialized on every call to scan(), and linear .includes() checks were performed on arrays containing dozens of items, creating a CPU bottleneck during large codebase analysis.

📊 Impact:

  • Reduces linear O(N) array lookups to O(1) hash set lookups for unsafeFuncs and nonSecretSubstrings.
  • Eliminates redundant array/function allocations on every .scan() invocation.
  • Consolidates 9 String.includes() calls for test/mock file detection into 1 compiled RegExp evaluation, significantly improving string matching throughput.
  • Overall scanner CPU overhead on large graphs should see a noticeable reduction.

🔬 Measurement:
Run AST graph processing on a large repository and observe improved processing times in the security scanner phase. Tests verify that detection accuracy remains identical.


PR created automatically by Jules for task 7520642348003200771 started by @giauphan

- Hoisted static arrays to module scope to prevent re-initialization
- Converted exact-match arrays to Sets for O(1) lookups
- Converted multiple string includes checks to single compiled RegExp
- Added unit tests for SecurityScanner

Co-authored-by: giauphan <122676967+giauphan@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

- Hoisted static arrays to module scope to prevent re-initialization
- Converted exact-match arrays to Sets for O(1) lookups
- Converted multiple string includes checks to single compiled RegExp
- Added unit tests for SecurityScanner

Fixed sonar cloud duplication and style issues on new test code

Co-authored-by: giauphan <122676967+giauphan@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

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