⚡ Optimize overpass amenity clustering - #16
Conversation
- Implement bounding box early exit in clusterAmenities loop to reduce O(N^2) Haversine calculations. - Pre-process amenity definitions to avoid redundant string splitting in the main loop. - Use Set for effectiveAmenities lookup. - Fix bug where coordinates at (0,0) were treated as falsy. - Performance improved by ~50% for typical datasets. Co-authored-by: julaub <22884742+julaub@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 implements a bounding box early-exit strategy in the
clusterAmenitiesfunction. It also optimizes the initial mapping phase by pre-processing amenity definitions and using aSetfor lookups.🎯 Why:
The previous implementation used a nested O(N^2) loop where every pair of amenities was compared using the expensive Haversine distance formula (
calculateDistance). This led to noticeable performance degradation as the number of amenities increased.📊 Measured Improvement:
Using a custom benchmark with 5,000 items in a 0.1-degree range:
For larger datasets (10,000 items), the duration dropped from ~2800ms to ~1400ms.
Correctness was verified with new tests in
js/api/overpass_clustering.test.jsand existing tests innpm test.PR created automatically by Jules for task 17679647930944249427 started by @julaub