Skip to content

⚡ Bolt: [O(1) Memory Allocation for jaccardSimilarity]#9

Open
garridolecca wants to merge 1 commit intomainfrom
bolt-optimize-jaccardsimilarity-8222480136370434911
Open

⚡ Bolt: [O(1) Memory Allocation for jaccardSimilarity]#9
garridolecca wants to merge 1 commit intomainfrom
bolt-optimize-jaccardsimilarity-8222480136370434911

Conversation

@garridolecca
Copy link
Owner

💡 What: The jaccardSimilarity function in src/utils/analysis-constants.ts was refactored. The old implementation used spreading ([...a]) and new Set() to calculate intersections and unions, which allocated memory dynamically per call. The new approach computes these sizes iteratively and mathematically (using the inclusion-exclusion principle).

🎯 Why: jaccardSimilarity is a utility used deeply inside clusterNewsCore - a performance-critical O(N²) inner loop running in both the main thread and web worker. Allocating O(N) memory during every comparison caused excessive garbage collection, heavily bottlenecking clustering speed as N grew.

📊 Impact: Reduces algorithmic memory complexity from O(N) to O(1) for this operation. This prevents memory spikes and limits CPU time spent on GC overhead during large clustering events.

🔬 Measurement: Verify by running npm run test:sidecar and npm run test:data which should all pass, and npm run lint:md and npm run typecheck to verify no types or styles broke. A journal entry was recorded in .jules/bolt.md.

Note: The user's request to "Make everything based on ArcGIS JavaScript API" was skipped because it directly violated the boundary against major architectural changes, as MapLibre GL and Deck.gl are the core mapping technologies in use.


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

Refactors `jaccardSimilarity` to compute the intersection size
iteratively and union size using the inclusion-exclusion principle.
This completely removes the linear memory overhead O(N) generated by
creating temporary Sets on each call.

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