The problem
Contour lines on a slippy map are usually pre-generated. One documented estimate puts pre-generated contour tiles at 100+ GB of storage for each variation (units, interval, smoothing). Every new style means another planet-wide batch run. The alternatives move the work elsewhere:
- In the browser:
maplibre-contourgenerates isolines from terrain tiles on the client, with a marching-squares implementation derived from d3-contour. It costs CPU on the weakest devices, and its own maintainers note that low-zoom tiles in hilly areas get slow. - On the tile server: MapLibre’s Martin (
convert_to_contour), TiTiler’scontoursalgorithm and MapServer’s contour layers trace contours per request. Per-tile latency then becomes your p99.
Either way, the contouring engine decides whether on-demand contours are viable.
Head-to-head, per tile
| Dataset | Grid · levels | isosweep1 thread | isosweep16 threads | GDAL 3.14-dev1 thread | ContourPy1 thread | VTK Flying Edges1 thread | Speed-upvs fastest 1-thread | Speed-upvs fastest overall |
|---|---|---|---|---|---|---|---|---|
| Copernicus 30 m DEM, 512 × 512 web-map tile window (Bernese Alps) real data | 512 × 512 · every 20 m | 15.8 ms | 3.76 ms | 69.9 ms | 183 ms | 144 ms | 4.4× | 19× |
| On-demand web map contour tile | 256 × 256 · 25 | 3.07 ms | 1.54 ms | 9.44 ms | 8.41 ms | 12.6 ms | 2.7× | 5.4× |
Median wall-clock time per full extraction, in-process, identical in-memory grid and iso-levels for every tool, each in its fastest documented configuration; lower is better. All line tools return assembled polylines. "Fastest overall" compares our best (1 or 16 threads) with the best result of any other library at any thread count; the shaded cell is that library. Measured November 2026 on Intel(R) Xeon(R) Platinum 8488C (48 cores / 96 threads) — AWS EC2 c7i.metal-24xl (dedicated bare-metal server, no hypervisor); Linux-7.0.0-1018-aws-x86_64-with-glibc2.39; turbo disabled; governor performance; THP never. Methodology.
Exact configuration of each library
- GDAL 3.14-dev (master) — Both versions built from source with identical options. callback = pure computation, points copied into a result buffer (as any caller must); generate_ex = native API into an in-memory layer (native result type), the layer reset before each call outside the clock. Published value = faster of the two. variant generate_ex {"api": "GDALContourGenerateEx (in-memory layer)"}
- ContourPy (serial) — variant serial_reused {"name": "serial", "line_type": "LineType.ChunkCombinedOffset", "reuse_generator": true}
- VTK Flying Edges (1 thread) — vtkImageData + filter pipeline built in prepare (zero-copy wrap, O(1)). vtkStripper joins segments into polylines (required for like-for-like output; MaximumLength unlimited so lines are fully joined) and is timed. variant sequential {"backend": "Sequential", "threads": 1}
Browser-side d3-contour is not in the table: it returns filled ≥-level polygons rather than isolines, so its timings aren’t like-for-like.
Multi-threading speeds up even a single tile (the multi-threaded column), which helps latency. A busy tile server is usually limited by throughput instead: run one tile per core, and the 1-thread column sets the throughput per core.
What it changes
- Contour styles become query parameters. Interval, units, smoothing and minimum length are applied per request. You stop storing one tile pyramid per style.
- Same source as hillshade. Contours come from the elevation tiles you already serve, so lines and terrain always match.
- Closed, classified output. Each closed contour knows whether it rings a summit or a depression, which drives index-contour styling and depression hachures without a second pass.
- A small C library, no runtime. isosweep links into a Rust, Go, C++ or Node tile server through a plain C ABI. For a client-side option, the same C library can be built into a native mobile app (on request).