From 505a772a813dcf15aa59fba9c2e2029203d40173 Mon Sep 17 00:00:00 2001 From: Dennis Falling Date: Mon, 25 May 2026 21:39:08 +0100 Subject: [PATCH] Cull offscreen markers to keep panning performant Marker is a native View that reprojects every camera frame even when offscreen, so the accumulated set was growing unbounded. Filter to the last-known viewport bounds before rendering; cached pins outside the viewport stay in memory and reappear instantly on pan-back. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/map/MapScreen.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/map/MapScreen.tsx b/src/map/MapScreen.tsx index eb2e4ac..a3aa49b 100644 --- a/src/map/MapScreen.tsx +++ b/src/map/MapScreen.tsx @@ -85,10 +85,18 @@ export function MapScreen() { }); }, [data?.elements]); - const elements = useMemo( - () => Array.from(elementsById.values()), - [elementsById], - ); + // Only render markers whose location falls inside the last-known viewport. + // is a native View — rendering offscreen ones still costs layout + // and reprojection on every camera frame, so we cull client-side. + const visibleElements = useMemo(() => { + if (!bounds) return []; + const {left, right, bottom, top} = bounds; + return Array.from(elementsById.values()).filter(el => { + if (!el.location) return false; + const {longitude: lng, latitude: lat} = el.location; + return lng >= left && lng <= right && lat >= bottom && lat <= top; + }); + }, [elementsById, bounds]); return ( @@ -98,7 +106,7 @@ export function MapScreen() { onRegionDidChange={onRegionDidChange}> - {elements.map(el => + {visibleElements.map(el => el.location ? (