⚡ [perf] Cull off-screen annotations during map snapshot rendering - #20
Conversation
|
👋 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. |
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>
d8206a0 to
cbee0ed
Compare
💡 What:
Added a boundary check (
rect.contains(MKMapPoint(annotation.coordinate))) inMapKitViewHost.swiftto 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:$O(N_{total})$ to $O(N_{visible})$ .
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
PR created automatically by Jules for task 3521068863553910900 started by @esenmx