Skip to content

⚡ Optimize isAnnotationSelected complexity - #2

Merged
esenmx merged 1 commit into
masterfrom
perf-optimize-isannotationselected-9734804635131331882
Jul 1, 2026
Merged

esenmx merged 1 commit into
masterfrom
perf-optimize-isannotationselected-9734804635131331882

Conversation

@esenmx

@esenmx esenmx commented Jul 1, 2026

Copy link
Copy Markdown
Owner

💡 What: Optimized isAnnotationSelected(with:) in AnnotationController.swift by replacing a nested search (getAnnotation) with a direct property access on the FlutterAnnotation model.

🎯 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:

  • Baseline Complexity: O(N * S) where N is map annotation count, S is selected annotations count.
  • New Complexity: O(S).

If the map has 1,000 annotations and 1 is selected, the operation now takes 1 step instead of 1,000 steps—a 1000x theoretical performance boost for this specific operation. This has a cascading impact as isAnnotationSelected is called heavily during UI updates (updateAnnotation(annotation:)).


PR created automatically by Jules for task 9734804635131331882 started by @esenmx

Co-authored-by: esenmx <43244505+esenmx@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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.

@esenmx
esenmx merged commit cba2d14 into master Jul 1, 2026
7 checks passed
@esenmx
esenmx deleted the perf-optimize-isannotationselected-9734804635131331882 branch July 1, 2026 14:43
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