⚡ Optimize isAnnotationSelected complexity - #2
Conversation
Co-authored-by: esenmx <43244505+esenmx@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: Optimized
isAnnotationSelected(with:)inAnnotationController.swiftby replacing a nested search (getAnnotation) with a direct property access on theFlutterAnnotationmodel.🎯 Why: The original code had an unintended O(N * S) time complexity per check (where N is the total annotations on the map, and S is the total number of selected annotations). When an annotation changed, checking whether it was selected involved searching through the map view's selected annotations, and for each selected annotation, performing a linear scan over all annotations to look up by ID. This became notably slow as the map populated with more pins.
The change replaces the O(N) lookup per loop with an O(1) casting and string equality check. The new complexity is strictly O(S), scaling based purely on the number of currently selected annotations, removing the impact of total map size.
📊 Measured Improvement:
Since this is an automated agent environment running on Linux without Swift or Xcode tools available natively, I could not generate physical profiling numbers or a Swift benchmark.
However, considering typical map usage scenarios:
O(N * S)whereNis map annotation count,Sis selected annotations count.O(S).If the map has
1,000annotations and1is selected, the operation now takes1step instead of1,000steps—a1000xtheoretical performance boost for this specific operation. This has a cascading impact asisAnnotationSelectedis called heavily during UI updates (updateAnnotation(annotation:)).PR created automatically by Jules for task 9734804635131331882 started by @esenmx