⚡ Bolt: [O(1) Memory Allocation for jaccardSimilarity]#9
⚡ Bolt: [O(1) Memory Allocation for jaccardSimilarity]#9garridolecca wants to merge 1 commit intomainfrom
Conversation
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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: The
jaccardSimilarityfunction insrc/utils/analysis-constants.tswas refactored. The old implementation used spreading ([...a]) andnew 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:
jaccardSimilarityis a utility used deeply insideclusterNewsCore- 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:sidecarandnpm run test:datawhich should all pass, andnpm run lint:mdandnpm run typecheckto 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