Skip to content

⚡ Bolt: [performance improvement] O(1) memory allocation in Jaccard Similarity clustering loop#18

Open
garridolecca wants to merge 1 commit intomainfrom
bolt-perf-jaccard-sim-o1-744591581506703694
Open

⚡ Bolt: [performance improvement] O(1) memory allocation in Jaccard Similarity clustering loop#18
garridolecca wants to merge 1 commit intomainfrom
bolt-perf-jaccard-sim-o1-744591581506703694

Conversation

@garridolecca
Copy link
Owner

💡 What: Optimized jaccardSimilarity in src/utils/analysis-constants.ts to iterate over sets directly and calculate the union mathematically, completely removing the intermediate array spreads and Set allocations.
🎯 Why: jaccardSimilarity is called heavily within the clusterNewsCore inner loop, which is an O(N²) operation. The previous implementation (new Set([...a].filter(x => b.has(x)))) created thousands of temporary arrays and sets every cycle, causing severe GC pressure and blocking the main thread.
📊 Impact: Reduces memory allocation to O(1) inside a critical path, significantly lowering the frequency and duration of garbage collection pauses. It prevents main thread blocking during large analysis batches.
🔬 Measurement: Verified the function operates in O(1) memory space. Ran full test:data suite, ensuring core analysis clustering and related signal logic tests continue to pass identically. Included an entry in the performance journal (.jules/bolt.md) documenting the pattern.

Note: Did not migrate to ArcGIS JS API per boundaries "Never Make architectural changes". Code maintains exactly the same functionality with the identical function signature.


PR created automatically by Jules for task 744591581506703694 started by @garridolecca

Replaced intermediate `Set` and `Array` allocations inside the `jaccardSimilarity` utility function with mathematical calculation of intersection and union sizes. This avoids heavy garbage collection in the O(N^2) inner clustering loop (`clusterNewsCore`). Added a `bolt.md` journal entry to document the learning.

Co-authored-by: garridolecca <10247583+garridolecca@users.noreply.github.com>
@google-labs-jules
Copy link

👋 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.

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