The problem
Real-time applications re-contour dynamic fields: fog-of-war visibility, influence maps, weather radar on a moving map, sensor fields on a tactical display, a level slider in an instrument UI. Every frame has a budget (16.7 ms at 60 fps), and contouring has to share it with everything else. GPU marching squares makes pixels, not geometry you can stroke, hit-test or label, and it competes with rendering. CPU marching squares costs every cell at every level every frame, and then leaves you to stitch the segments together.
Per-frame cost, head-to-head
| Dataset | Grid · levels | isosweep1 thread | isosweep16 threads | VTK Flying Edges1 thread | GDAL 3.14-dev1 thread | ContourPy1 thread | VTK Flying Edges8 threads | ContourPy64 threads | Speed-upvs fastest 1-thread | Speed-upvs fastest overall |
|---|---|---|---|---|---|---|---|---|---|---|
| Interactive 60fps level scrubbing | 1,024 × 1,024 · 25 | 14.0 ms | 3.18 ms | 93.9 ms | 60.2 ms | 112 ms | 36.3 ms | 25.7 ms | 4.3× | 8.1× |
| On-demand web map contour tile | 256 × 256 · 25 | 3.07 ms | 1.54 ms | 12.6 ms | 9.44 ms | 8.41 ms | 10.1 ms | 6.15 ms | 2.7× | 4.0× |
| Adaptive RT isodose display | 512 × 512 · 16 levels (interval 1/16) | 1.00 ms | 0.67 ms | 9.92 ms | 7.44 ms | 16.9 ms | 4.95 ms | 7.72 ms | 7.4× | 7.4× |
| Vascular network segmentation | 1,024 × 1,024 · 10 | 2.64 ms | 1.11 ms | 23.9 ms | 23.6 ms | 42.8 ms | 6.72 ms | 9.77 ms | 9.0× | 6.0× |
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
- 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}
- 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 (best SMP backend × threads) — 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 smp {"backend": "STDThread", "threads": 4}
- ContourPy (threaded, best threads × chunks) — variant threaded_reused {"name": "threaded", "line_type": "LineType.ChunkCombinedOffset", "thread_count": 8, "chunk_count": [4, 4], "reuse_generator": true}
Why it fits real-time and embedded
- Cost follows the picture. The sweep’s work scales with the contours it emits, so quiet or sparse fields (most fog-of-war frames) cost far less than the grid size suggests.
- One core is enough. The single-thread column is the one that matters on a game thread or an embedded CPU, and leaves the other cores for everything else.
- Geometry, not pixels. Ordered, closed, classified polylines that you can stroke, fill, triangulate, label or feed to navigation and collision code.
- Portable C11. No runtime, no GPU, no third-party dependencies. It builds with a C11 compiler and POSIX threads, ARM included, and can run on your own thread pool instead. Engine plug-ins (Unity, Unreal) and safety-standard support can be scoped under an enterprise licence.