Skip to main content

Optional acceleration

Large independent buffers can benefit from persistent application workers. Small batches often finish sooner on the calling thread. Keep the ordinary projection engine as the numerical implementation and measure the complete application operation, including ownership changes, startup and scheduling. math.gl does not create workers automatically or switch precision/backends.

Measured worker profileโ€‹

The development runner compares a prepared calling-thread engine with one and two persistent module workers. It uses Mercator and UTM, Float32/Float64, both directions and XYZM, at 1,000, 10,000 and 100,000 points. Seven rotated samples follow three warmups. Each sample includes a fresh input copy, partitioning for two workers, transfers, queueing and processing. Cold imports and worker preparation are recorded separately; add those costs when evaluating one-shot use. Every returned coordinate must exactly match the ordinary engine, including M. Transfer detachment and returned buffers after a failed record are also checked.

Local Apple M2 / macOS arm64 measurements on October 4, 2026, for 100,000 Float64 forward XYZM records:

ProjectionBrowserCalling threadOne workerTwo workers
Web MercatorChromium 151.0.7922.343.8 ms7.7 ms4.2 ms
UTM 31NChromium 151.0.7922.3428.9 ms39.5 ms19.7 ms
Web MercatorWebKit 26.53 ms4 ms5 ms
UTM 31NWebKit 26.527 ms31 ms11 ms

Two workers give approximately 1.5โ€“2.5ร— throughput for the measured UTM case. Results vary by browser, buffer size, precision and direction. Many small cases are below the timer's useful resolution; no speed ratios should be inferred from zeros or submillisecond samples. Worker startup ranged from 10 to 267 ms in these local runs and can outweigh the warm gain. Raw samples, p10/p90, timing-limit/variation flags, source/workload hashes, engine/bootstrap sizes and startup costs are retained in Chromium and WebKit reports. These observations qualify this workload, not universal hardware/browser performance. CI executes correctness and records measurements in Chromium, Firefox and WebKit without a speed threshold.

node modules/geospatial/scripts/projection/benchmark-workers.mjs \
--browser chromium --points 1000,10000,100000 --samples 7 \
--output /tmp/projection-workers.json

For repeated batches, compare main import + preparation + N ร— main median with both worker startups + N ร— two-worker median. Add application join costs to the worker total. Reporting startup separately makes the amortization decision explicit; a warm speedup alone does not justify moving a single small batch.

Use a worker in an applicationโ€‹

Keep an engine prepared inside a module worker and preload its dependencies once. The following small worker illustrates ownership and failure handling for one batch at a time. Configure its CRS and plugins for the application, bundle it normally and keep its lifetime under application control.

// projection-worker.ts
import {ProjectionTransform} from '@math.gl/geospatial/projection-core';
import {universalTransverseMercator} from '@math.gl/geospatial/projection-projections-utm';
const projection = new ProjectionTransform({
to: 'EPSG:32631', projections: [universalTransverseMercator]
});
self.postMessage({ready: true});
self.onmessage = ({data}) => {
const {id, coordinates, dimension, inverse} = data;
try {
projection[inverse ? 'unprojectFlatSync' : 'projectFlatSync'](coordinates, dimension);
self.postMessage({id, coordinates}, [coordinates.buffer]);
} catch (error) {
// Valid prefix may be committed. Return ownership even on a numerical failure.
self.postMessage({id, coordinates, error: String(error)}, [coordinates.buffer]);
}
};

After the worker reports readiness, send an owned, full-buffer typed array:

const worker = new Worker(new URL('./projection-worker.ts', import.meta.url), {type: 'module'});
// Install ready/result/error handlers before submitting work.
worker.postMessage({id: 1, coordinates, dimension: 4, inverse: false}, [coordinates.buffer]);
// coordinates.buffer is now detached; use the returned coordinates on completion.

Use request IDs, a bounded queue and error/termination handling. A fatal worker exit cannot return a transferred buffer; retain source data or provide a recovery policy if needed. Transferring a view transfers its entire backing buffer, so copy subviews when unrelated data shares that buffer. Do not transfer epoch or payload arrays that are still in use. Split independent records for parallel work; return results in input order and account for join costs. The evaluation measures partitioned buffers without a final joined-buffer copy. Returning a single merged buffer would add another application cost. Workers also move work off the UI thread; responsiveness and elapsed throughput are separate reasons to use them. See MDN worker guidance and transferable ownership.

Wasm, SIMD and visualization GPU boundariesโ€‹

The runner records Wasm SIMD validation and WebGPU availability as capability probes only. It does not contain a Wasm/GPU projection algorithm or benchmark those backends. A future implementation needs independent numerical references, precision/domain/failure and payload contracts, cold loading and bundle costs, complete upload/dispatch/readback measurements, and a justified crossover point. Capability availability is not evidence of a speed advantage. GPU visualization coordinates cannot silently replace double-precision geodetic transformations. The package supplies no binary projection backend or additional third-party implementation.