TL;DR

  • Problem: Drawing polygons as separate <Polygon> components with react-native-maps caused long frame stalls, high input latency and high memory use on a rugged field tablet (Samsung Galaxy Tab Active Pro, SM-T547, Android 11, 4 GB RAM).
  • Change: I moved to MapLibre Native with a single GeoJSONSource and GPU style layers, instead of one <Polygon> component per shape.
  • Results (release builds, scripted swipes): MapLibre drew the whole loaded dataset with no viewport cap, and still used less memory: total memory (PSS) was about 22%–27% lower, Java heap allocation about 67%–75% lower, and Android View objects dropped from 225 to 142 in the main session (up to 427 in earlier sessions). Both versions kept the map surface at about 57–59 FPS on average. MapLibre had fewer long frames and lower input latency.
  • Caveats: One device, Android only, one run per session, and MapLibre drew the whole data source (up to 2,000 polygons) while the react-native-maps version drew at most 120.

1. Introduction: Dense Geographic Data on Mobile Devices

Showing a few markers on a map sounds easy, and when I imagined showing a few polygons, I thought that would be easy too. I was naive. The first time I asked the API for 1,000 polygons on our field tablet, the app froze for several seconds.

The project is a geographic information system (GIS) app that runs on rugged field tablets (Samsung Galaxy Tab Active Pro / SM-T547 — Android 11, Snapdragon 670, Adreno 615, 4 GB RAM, 60 Hz). Its main purpose is to show hundreds or even thousands of polygons on Google Maps (on iOS I first used Apple Maps, and as far as I could tell it struggled in the same way: the bottleneck was the library, not the basemap). With 50–100 polygons, performance was fine. I benchmarked on this tablet on purpose: it is the hardware the app is used on, and on a flagship phone the problem was much harder to see (see Section 9).

With more polygons, I ran into three problems:

  • Stalls while panning: In areas with dense polygon clusters, the map stuttered while panning and responded to touches late.
  • High memory use: The app took a large share of the tablet’s 4 GB of RAM, on a device that also runs background services.
  • Freezes while loading: Fetching and processing the API response, which was over 10 MB, blocked the JS thread.

This article focuses on rendering. I come back to the loading freeze at the end of Section 4. Checking the polygons against the user’s current location, another heavy job in the app, is outside the scope of this article.

Tech stack:

  • Framework and runtime: React Native 0.84.1 (React 19.2.3, Hermes engine)
  • Map engine: @maplibre/maplibre-react-native (^11.5.0) (previously react-native-maps)
  • State management: Redux Toolkit (^2.11.2)
  • Geometry processing: @turf/turf (^7.3.4)

2. Why the First Architecture Hit a Wall

In the first version of the project I used react-native-maps, one of the common map solutions in the React Native ecosystem. In the usual declarative React style, every polygon on screen was rendered as its own <Polygon> component inside a .map() loop:

// OLD APPROACH: one React Native component per polygon {visiblePolygons.map((polygonItem) => ( <Polygon key={polygonItem.id} coordinates={polygonItem.coordinates} strokeColor={COLOURS.POLYGONSTROKE} fillColor={COLOURS.POLYGONFILL} strokeWidth={2} /> ))} 

This works fine for a small number of polygons. As the data got denser, clear differences showed up at the operating-system and window-layer level.

2.1. Window Layer Structure and the Rise in Native Views

The <Polygon> component in JSX is more than just a virtual drawing command. In the Android implementation, there is a matching View for each of these components, which maintains the Java equivalent of all coordinates (one LatLng per vertex) and incorporates the shape into the Google Maps SDK, which then draws the shape using its own rendering engine. Even though the View doesn’t actually draw the polygon, it still needs to exist and maintain its state.

The layer list from dumpsys SurfaceFlinger --list shows a basic architectural difference between the two libraries. react-native-maps puts all UI elements and the map, polygons included, into a single main window layer:

ActivityRecord{… com.example.gisapp.dev/com.example.gisapp.MainActivity …}#0 … com.example.gisapp.dev/com.example.gisapp.MainActivity#0 com.example.gisapp.dev/com.example.gisapp.MainActivity$_<pid>#1 


dumpsys SurfaceFlinger --list on the SM-T547 (package name replaced). Google Maps renders into the app’s main window.

MapLibre opens a separate SurfaceView layer for the map:

ActivityRecord{… com.example.gisapp.dev/com.example.gisapp.MainActivity …}#0 … com.example.gisapp.dev/com.example.gisapp.MainActivity#0 Background for -SurfaceView - com.example.gisapp.dev/com.example.gisapp.MainActivity@…#0 SurfaceView - com.example.gisapp.dev/com.example.gisapp.MainActivity@…#0 com.example.gisapp.dev/com.example.gisapp.MainActivity$_<pid>#1 Bounds for - com.example.gisapp.dev/com.example.gisapp.MainActivity@0#0 


MapLibre adds its own SurfaceView layer for the map.

With react-native-maps, dumpsys meminfo counted many more View objects than with MapLibre (see the table in Section 5.1), even though the number of views attached to the window was about the same in both versions. The difference is the per-polygon Views, which exist in memory but are not part of the visible layout. I did not measure their measure/layout cost separately.

3. An Intermediate Step: JS-Level Optimizations and Viewport Filtering

Before replacing the map library, I tried to relieve the existing architecture with four optimizations at the React and algorithm level:

  1. 2D spatial hash grid (viewport filtering): Instead of scanning every polygon, I built a spatial index (spatialIndex.ts) that splits the map into virtual cells of 0.05 degrees (~5.5 km). It returns the polygons that fall into the visible region, expanded to 120% of its size, and caps the result at MAX_VISIBLE_POLYGONS = 120. Over time I tried different values for the cap to find the best balance. 120 was the last one.
  2. React render isolation and debounce: I moved the spatial grid into a useRef so index updates stay out of the render cycle, and added a 50 ms debounce to the viewport query that runs on camera moves. If the visible polygons were the same as after the previous camera move, I skipped the state update, so React didn’t re-render them.
  3. Asynchronous chunking: To avoid processing all polygons in one pass and blocking the JS thread, I processed them in chunks of 75 and called setTimeout(..., 0) after each chunk. For each vertex, the normalizer created two copies: [lon, lat] for GeoJSON and { latitude, longitude } for <Polygon>:
// Simplified: the normalizer in the react-native-maps version const CHUNK_SIZE = 75 export const normalizeFeaturesAsync = async (features: any[]): Promise<any[]> => { const result: any[] = [] for (let i = 0; i < features.length; i += CHUNK_SIZE) { const end = Math.min(i + CHUNK_SIZE, features.length) for (let j = i; j < end; j++) { // ... validate the geometry, take the outer ring of each polygon for (const [lon, lat] of ring) { polygonCoords.push({ latitude: lat, longitude: lon }) // for <Polygon> closedRingCoords.push([lon, lat]) // for GeoJSON } // ... close the ring, build an ID, push the Feature (with both copies) } // Yield to the event loop between chunks if (end < features.length) { await new Promise((resolve) => setTimeout(resolve, 0)) } } return result } 
  1. Polygon simplification in JavaScript: I also tried simplifying the geometry with @turf/simplify before passing it to <Polygon>. It broke the geometry: the output was not always a valid polygon any more, and it looked different from the original polygon data, so I removed it completely.

Why It Wasn’t Enough: The Visible Polygon Cap

The optimizations helped to make the map more usable at the local level, but they introduced a limitation for the product. Once the user zoomed out to view the entire region, the MAX_VISIBLE_POLYGONS = 120 limit excluded a lot of polygons and made the map look incomplete. Even with the final value of 120, the UI would occasionally freeze, and I believe this was because of the native polygon objects.

4. The Architecture Change: MapLibre’s GPU Vector Pipeline

To fix the root cause, I stopped creating one native object per polygon. Switching libraries wasn’t my own idea at first: an AI coding assistant suggested MapLibre, and I decided to give it a try. I removed react-native-maps and moved to MapLibre Native (@maplibre/maplibre-react-native, android-sdk-opengl), a C++ core that renders with OpenGL ES.

4.1. The SurfaceView Architecture and a Single GeoJSONSource

As the layer lists in Section 2.1 show, MapLibre draws the map on its own SurfaceView layer. Polygons are no longer part of the Android View hierarchy. The engine keeps them on the C++ side and draws them on this surface with the GPU. That is why the View count stays low even with the whole data source on the map:

// NEW APPROACH: polygons are drawn from a single source with GPU layers export const PolygonLayer = memo(({ features, selectedZoneId, onPolygonPress }) => { const geoJsonString = useMemo(() => { if (!features || features.length === 0) return EMPTY_FEATURE_COLLECTION return JSON.stringify({ type: 'FeatureCollection', features }) }, [features]) const activeSelectedId = selectedZoneId || '' return ( <GeoJSONSource id="polygons-source" data={geoJsonString} tolerance={0.5} buffer={64} maxzoom={16} onPress={onPolygonPress} > <Layer id="polygons-fill" type="fill" paint={{ 'fill-color': COLOURS.POLYGONFILL, 'fill-opacity': 0.45, }} /> <Layer id="polygons-line" type="line" paint={{ 'line-color': [ 'case', ['==', ['get', 'zone_id'], activeSelectedId], COLOURS.POLYGON_HIGHLIGHT_STROKE, COLOURS.POLYGONSTROKE, ], 'line-width': [ 'case', ['==', ['get', 'zone_id'], activeSelectedId], 4, 2, ], }} /> </GeoJSONSource> ) }) 

I expected native heap to grow, because the polygon data now lives in MapLibre’s C++ engine instead of in Java objects. It did in the main session (223 MB → 250 MB), but not in the other two, so I can’t say it consistently grows. For a high-level overview of MapLibre Native’s internals (threading model, style and render split), see the project’s ARCHITECTURE.md.

4.2. Data-Driven Styling Instead of Re-Rendering

In the old version, polygons weren’t tappable. When the user tapped the map, I checked the tapped point against every polygon in JavaScript with turf’s booleanPointInPolygon, and there was no highlight for the selected polygon. With MapLibre, GeoJSONSource’s onPress returns the tapped feature directly, because the engine does the hit test natively. When the selection changes, the engine re-evaluates the style, and React doesn’t re-render anything per polygon.

4.3. Dynamic Geometry Handling (tolerance, buffer and maxzoom)

In Section 3 I tried @turf/simplify on the JavaScript thread, and it broke the geometry. Simplifying once, in JavaScript, also fixes the level of detail for every zoom level. Besides, simplifying on the JS side added extra work to the JS thread.

MapLibre Native splits GeoJSON data into vector tiles in the background using the geojson-vt library, and simplifies per tile and per zoom level, off the JS thread. Three options control this (see the MapLibre Style Specification):

  • tolerance={0.5}: The Douglas-Peucker simplification tolerance (an algorithm I only learned about while tuning this). Higher values give simpler geometry and better performance. Geometry is simplified when the map is zoomed out, and more of the original detail shows as you zoom in.
  • buffer={64}: The tile buffer width in pixels (default 128). A lower value reduces duplicated geometry between neighboring tiles, but a value that is too low can cause clipping at tile edges.
  • maxzoom={16}: The highest zoom level at which vector tiles are generated. Above it, the existing data is scaled up (overzooming).

The defaults are tolerance: 0.375, buffer: 128 and maxzoom: 18. My values are moderate changes, and the build I benchmarked used them. I did not isolate the effect of these settings on memory.

What happened to the loading freeze? With <Polygon> gone, the normalizer keeps only one [lon, lat] copy of each coordinate and rounds it to 5 decimal places (the raw data came with 8). After the move, the multi-second freeze on the first fetch was gone. There is still a short pause, because parsing the 10 MB response and building the source string still run on the JS thread, but it no longer feels like the app is stuck. I tried to measure the load phase, but with adb shell dumpsys netstats I could only see how much data was downloaded, not how long processing took. So this part is my impression, not a benchmark result.

5. Field Tests and Results

To remove the variability of a human finger, I ran a repeatable, scripted benchmark on the tablet. The script and the raw reports are in this Gist (see Reproducing the Benchmark at the end).

Test conditions:

  • Release APK builds. The main pair was recorded right after a reboot, with the two apps tested one after the other (Google Maps first). The two other clean sessions were recorded while the device had been on for hours and was in normal use.
  • A mock location app pinned the device to the same fixed coordinates for both apps, so both started over the same area and the same polygon data, and no new data was fetched during the swipes.
  • 10 cycles (20 swipes) of identical horizontal swipes across the middle of the screen, about 33 seconds in total, no zooming. Frame statistics were reset right before the swipes, so startup was not counted.
  • Basemaps: Google Maps Hybrid (satellite imagery plus a road and label layer) in the Google Maps build, ESRI World Imagery raster tiles in the MapLibre build.
  • scrcpy screen mirroring was on. Perfetto tracing was off.

5.1. Comparison Table

The main columns show the main pair. The last column shows the range across all three clean sessions.

Metric react-native-maps MapLibre Range across clean sessions
Polygons drawn Up to 120 (viewport-filtered) Up to 2,000 (whole data source) —
Android Views (meminfo) 225 142 Google Maps: 225–427 / MapLibre: 141–142
Java heap (Dalvik Alloc) 43.0 MB 14.0 MB Google Maps: 43.0–57.7 MB / MapLibre: 14.0–14.8 MB (~67% to ~75% lower)
Total memory (TOTAL PSS) 652.2 MB 510.9 MB Google Maps: 652–817 MB / MapLibre: 511–595 MB (~22% to ~27% lower)
Longest UI frame (gfxinfo) 133 ms 29 ms Google Maps: 133–550 ms / MapLibre: 26–150 ms
Slow UI thread 5 frames 0 frames Google Maps: 5–17 / MapLibre: 0–3
High input latency 347 frames (23.1%) 80 frames (9.1%) Google Maps: 347–801 / MapLibre: 80–240

The full gfxinfo and meminfo reports behind this table are in the Gist.

Read the frame rows with one thing in mind. The results themselves didn’t surprise me: when I used the app, loading and panning already felt much better with MapLibre. The frame counts were the odd part. For the same 20 swipes, MapLibre had almost half as many frames (880 vs 1,503).

I started testing with the tools on the device itself: Profile HWUI rendering and Show refresh rate in Developer options. They are good for a quick look, but they only tell part of the story. The layer lists in Section 2.1 explained the frame counts: dumpsys gfxinfo only counts frames drawn by the app’s own window. With Google Maps, the map is part of that window, so the frame rows include the map. With MapLibre, the map is drawn on its own SurfaceView, so the frame rows describe only the React Native UI on top of the map. The rows still matter, because touch input is handled on the UI thread, but they do not compare the two map engines one to one. For the smoothness of the map itself, see Section 5.2.

5.2. Average FPS Is Similar, the Tail Differs

To measure the map itself, I read frame timestamps per layer from SurfaceFlinger:

Layer Active intervals 1 vsync 2 vsync ≥3 vsync Avg. FPS
Google Maps main window 1,618 98.5% 0.9% 9 58.3
MapLibre SurfaceView 1,209 94.4% 5.5% 1 56.7
MapLibre main window 968 97.6% 2.4% 0 58.6

“Active intervals” are frame-to-frame intervals after removing gaps of 100 ms or more (the pauses between swipes). One vsync is the 16.7 ms frame budget of a 60 Hz display. Main session.

The averages are close. MapLibre misses a single vsync more often on the map surface, possibly when the engine uploads new tiles to the GPU, but I did not verify this. What almost disappears are the deep stalls of three vsyncs or more. Together with the lower input latency in Section 5.1, that is the difference you feel when you pan.

Why does it feel smoother? (observations and hypotheses)

  • Hypothesis 1, layer separation: Google Maps handles the UI and the polygons in one window layer, while MapLibre draws the map in a separate SurfaceView layer (Section 2.1). This separation may reduce how much map movement interacts with the native UI thread.
  • Hypothesis 2, memory pressure and garbage collection: Instead of managing up to 120 separate polygon objects, MapLibre keeps the data in a single GeoJSON source. The Java heap shrank sharply (Section 5.1), which probably reduced allocation and garbage collection pressure. When I watched the Google Maps build in Android Studio’s live memory profiler, I saw several garbage collection events while panning. I also profiled the MapLibre version, but not under the same conditions, so I can’t compare the two directly. Heap dumps from earlier builds point the same way: the app heap of the react-native-maps build held about 904,000 objects (81.9 MB shallow size), the MapLibre build about 183,000 (36.3 MB). These were not the benchmarked APKs, so I treat this as a hint, not a measurement.


Live telemetry of an earlier react-native-maps build with the same polygon rendering approach (not the benchmarked APK). Each trash can icon is a garbage collection event.


App heap of earlier builds, react-native-maps vs MapLibre (not the benchmarked APKs).

6. Migration Notes

A few things I had to change or learn when moving from react-native-maps to MapLibre:

  • Check the tile provider’s terms. Free tile endpoints come with terms of use. Read them before you ship, especially for commercial use and for offline downloads, and keep the required attribution visible on the map.
  • Coordinates flip. react-native-maps takes { latitude, longitude } objects. GeoJSON uses [longitude, latitude] arrays. Swapped coordinates are an easy mistake when you move existing data over.
  • Pass the source data as a string. GeoJSONSource accepts a JSON string. I build it once in a useMemo so it isn’t serialized again on every render.

7. When to Use MapLibre, When to Use react-native-maps

  • react-native-maps can be the better choice when the map only shows a few markers, a simple route or a limited number of shapes, or when you need Google Maps or Apple Maps as the basemap. Setup is fast and it needs no style server.
  • MapLibre can be the better choice when the app has dense polygon data, complex GeoJSON boundaries, custom vector or raster tile layers, or offline map packages. Handing the map drawing to a GPU pipeline on a separate SurfaceView is a strong option for UI smoothness and memory control.

What about Mapbox? I looked at Mapbox later, but its free tier comes with usage limits, so I never tried it and can’t compare the two here.

8. Conclusions and Design Principles

  1. Don’t split geographic data into separate JSX components. Rendering many polygons as separate React components (<Polygon>) increases the native View count, and at least in React Native it’s not good practice. Give the data to one GeoJSONSource and let GPU style layers (<Layer type="fill">, <Layer type="line">) draw it.
  2. Leave geometry simplification to the engine. In the react-native-maps version I simplified polygons in JavaScript, and it broke the geometry (see Section 3). MapLibre’s tolerance and maxzoom options do this per tile and per zoom level, off the JS thread.
  3. Let the engine do hit testing and highlighting. Use the source’s onPress to find the tapped feature, and data-driven style expressions (['case', ...]) inside <Layer> to highlight it, instead of doing both in JavaScript.
  4. Optimize the data shape. Keep one copy of each coordinate, round to a sensible precision and validate closed rings on the client. This should help reduce memory pressure. (I did not measure this separately.)

If I hadn’t needed to process the polygon data on the device, I would have simply shown it from a WMS server as map images. There already was one, but because I had to work with the data itself, it wasn’t enough for this app. Without that requirement, most of these optimizations wouldn’t have been necessary.

9. Limitations

Please read the findings with these limits in mind:

  1. One device, one platform. All scripted tests ran on a single physical model (Samsung Galaxy Tab Active Pro / SM-T547) with Android 11. I also tried both versions on a Galaxy S23 (Android 15). Panning was smooth on both, but with Google Maps I could still feel a stutter for 2–3 seconds while the first data was fetched and drawn. MapLibre ran smoothly in all my tries. I didn’t benchmark the S23, because I thought it wouldn’t show as much as the tablet. The bottleneck in this article shows up most on low-end hardware, and a flagship phone can hide much of it. On iOS the app first used Apple Maps. I think it had the same problems, but I couldn’t confirm it: I didn’t have a low-spec iOS device, and I didn’t run the scripted tests on a physical iOS device.
  2. Test scope. Each session recorded a single run of 20 horizontal pan gestures. Zooming, rotation and free user interaction were not part of the automation. The screen was mirrored with scrcpy during the tests, which can add a small load to screen composition, but it was on for both apps.
  3. Different layer architecture. In the Google Maps build, the measured main window layer also contains the UI controls. In the MapLibre build the map is drawn on a separate SurfaceView layer. The layer metrics of the two versions therefore do not describe an identical structure, and the gfxinfo frame metrics cover the map only in the Google Maps build (see Section 5.1).
  4. Unequal workload. The Google Maps build drew at most 120 polygons through viewport filtering, while the MapLibre build received the whole loaded data source (up to about 2,000 polygons; each API request returns at most 1,000). Both apps were tested at the same location, but the 120 cap is an upper bound, and I did not log how many polygons were loaded or drawn in the test region.
  5. Different basemaps. Google Maps used Hybrid (satellite plus road and label layer), MapLibre used ESRI World Imagery raster tiles. They can affect network traffic and texture cache differently.

Reproducing the Benchmark

The benchmark script, the SurfaceFlinger analysis script and the full meminfo and gfxinfo reports of the main session (package name replaced) are in the Gist: gist.github.com/be812d12041e6c8509b567513fab2ea0. The script resets gfxinfo, runs the swipes with adb shell input swipe, then collects dumpsys gfxinfo, dumpsys meminfo, per-layer frame timestamps from dumpsys SurfaceFlinger --latency (polled once per second during the swipes), battery temperature and network totals from dumpsys netstats.