Skip to content

⚡ [perf] Cull off-screen annotations during map snapshot rendering - #20

Merged
esenmx merged 2 commits into
masterfrom
perf-cull-snapshot-annotations-3521068863553910900
Aug 23, 2026
Merged

⚡ [perf] Cull off-screen annotations during map snapshot rendering#20
esenmx merged 2 commits into
masterfrom
perf-cull-snapshot-annotations-3521068863553910900

Conversation

@esenmx

@esenmx esenmx commented Aug 22, 2026

Copy link
Copy Markdown
Owner

💡 What:
Added a boundary check (rect.contains(MKMapPoint(annotation.coordinate))) in MapKitViewHost.swift to cull annotations that lie outside the snapshot's visible region (mapRect) prior to drawing.

🎯 Why:
During snapshot creation (takeSnapshot), all unhidden annotations were being drawn regardless of whether they were inside the snapshot's visible bounds. Drawing off-screen annotation views or images incurs unnecessary CPU and rendering overhead. Overlays already performed a similar bounding check (overlay.intersects?(rect)), and annotations now follow the same optimization pattern.

📊 Measured Improvement:
Because native Swift execution is not available in the Linux environment, running native benchmarks was impractical. Theoretically, this culling avoids rendering work for every off-screen annotation, reducing drawing complexity from $O(N_{total})$ to $O(N_{visible})$.


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

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

google-labs-jules Bot and others added 2 commits August 23, 2026 19:12
Cull annotations outside the snapshot mapRect using
rect.contains(MKMapPoint(annotation.coordinate)) before drawing.

Co-authored-by: esenmx <43244505+esenmx@users.noreply.github.com>
Point containment in map space (`rect.contains(MKMapPoint(coordinate))`)
dropped annotations whose coordinate sits just outside the region while
their icon straddles the image edge; MKMapView renders those on screen.

Test the drawn frame against the image's pixel bounds inside
`drawAnnotations` instead: fully off-image annotations skip the expensive
`drawHierarchy(afterScreenUpdates: true)` / `image.draw(at:)`, while
partially visible edge annotations still draw their in-frame portion.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@esenmx
esenmx force-pushed the perf-cull-snapshot-annotations-3521068863553910900 branch from d8206a0 to cbee0ed Compare August 23, 2026 16:14
@esenmx
esenmx merged commit 83f58ed into master Aug 23, 2026
7 checks passed
@esenmx
esenmx deleted the perf-cull-snapshot-annotations-3521068863553910900 branch August 23, 2026 16:25
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