Skip to content

⚡ Bolt: [performance improvement]#254

Closed
raccioly wants to merge 1 commit into
mainfrom
bolt/optimize-regexp-iteration-3732714359725914287
Closed

⚡ Bolt: [performance improvement]#254
raccioly wants to merge 1 commit into
mainfrom
bolt/optimize-regexp-iteration-3732714359725914287

Conversation

@raccioly

Copy link
Copy Markdown
Owner

💡 What: Replaced nested .filter() and .some() cross-comparisons between two arrays with a single nested loop that populates two Set objects for O(1) membership lookups.

🎯 Why: To fix an O(N*M) algorithmic bottleneck. Even though the regular expressions were already pre-compiled (avoiding RegExp instantiation overhead), iterating through the arrays repeatedly via array.filter(a => !otherArray.some(b => match(a, b))) caused redundant iterations and checks across the entire array for every single element.

📊 Impact: Reduces array iteration and matching attempts from $3 \times N \times M$ down to a single $N \times M$ pass. Tests run much faster when matching large project directories.

🔬 Measurement: Run the test suite (node --test tests/*.test.mjs) to verify correctness, and test against a large test directory to observe the reduced CPU overhead.


PR created automatically by Jules for task 3732714359725914287 started by @raccioly

Replaces a severe O(N*M) algorithmic bottleneck in `diffTests`
where two arrays were cross-compared using nested `.filter()`
and `.some()` loops. Even though RegExps were pre-compiled,
the array iteration itself triggered redundant evaluations.

This converts the logic to a single pass that populates two
`Set` objects, enabling O(1) membership checks to extract
`onlyInCode`, `onlyInDocs`, and `matched` arrays.

Co-authored-by: raccioly <63126795+raccioly@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.

@raccioly raccioly closed this Jul 6, 2026
@raccioly raccioly deleted the bolt/optimize-regexp-iteration-3732714359725914287 branch July 6, 2026 00:57
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