⚡ Bolt: [performance improvement] optimize jaccardSimilarity memory allocation#14
⚡ Bolt: [performance improvement] optimize jaccardSimilarity memory allocation#14garridolecca wants to merge 1 commit intomainfrom
Conversation
…llocation 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 optimization implemented is avoiding creating intermediate
SetandArrayobjects insidejaccardSimilarityfunction.🎯 Why: The
jaccardSimilarityfunction is called inside the O(N^2) inner loop ofclusterNewsCore. It creates multiple intermediate sets ([...a].filter(),new Set([...a, ...b])), causing a huge amount of allocations and making GC pressure skyrocket. The new implementation avoids allocations by manually iterating to find intersections and using the inclusion-exclusion principle to calculate union mathematically (|A ∪ B| = |A| + |B| - |A ∩ B|).📊 Impact: Reduces GC pressure significantly for large arrays, improving the performance inside O(N^2) operations and drastically reducing memory churn.
🔬 Measurement: The tests for
jaccardSimilaritycontinue to pass perfectly since the output is exactly the same, but you can benchmark this function and see its speed improved.Note: Also documented this performance antipattern in
.jules/bolt.mdbased on the given instructions. Also ignored request to make everything based on ArcGIS JavaScript API as it explicitly states to avoid architectural changes.PR created automatically by Jules for task 6657432897880950191 started by @garridolecca