# Parse throughput The two usual ways to speed up a parser are to batch the work or to run it concurrently. In Node, one parse cannot overlap another in the same process, so concurrency leaves throughput at 1.00x. A batched graph gives at most 1.12x (1.24x for fp32) and is slower above B=8. Worker threads are the route this page recommends. The reasons are not visible from the call site, so this page records the measurements for anyone considering a batch path. The measurements were taken on 2026-07-16 against the v6.3.0 model shipped at the time (`v264-country-softguard`, int8) on a 16-core machine. They also apply to 6.5.0. That release changed only the weights on the same int8 graph shape, and parse latency depends on the graph shape rather than on the weights. No later release was measured. The graph has changed since: the measured graph took eight inputs (token ids, the mask and three channels), and the en-us graph at 10.7.0 takes token ids, the mask, five channels and a locale hint ([Python removal plan, ยง4.1](./2026-10-29-python-removal-plan.mdx)). ## Where the time goes The ONNX forward pass takes **93.2% of a parse**. Tokenization, anchor/gazetteer/country channel lookups, Viterbi, and tree construction add up to 0.25 ms, under 7% of the wall clock. If the forward pass took no time, parsing would be 14.6x faster. Every change below tries to capture part of that 14.6x. Concurrency fails because the JavaScript thread is blocked for the whole inference. A batched graph gains little because the cores are already busy: ONNX Runtime uses **8.02 cores on a single batch=1 inference**, so little idle capacity remains. ## Concurrency Throughput stays at 1.00x from one concurrent parse to sixteen in the same process, for both parse and full geocode: | concurrent | parse addr/s | scaling | | ---------: | -----------: | ------: | | 1 | 274.0 | 1.00x | | 2 | 276.1 | 1.01x | | 4 | 279.4 | 1.02x | | 8 | 274.6 | 1.00x | | 16 | 274.5 | 1.00x | Two things block the thread, and either one by itself is enough to prevent overlap: - **`onnxruntime-node`'s `session.run()` blocks the JavaScript thread.** It doesn't hand work to the libuv pool. `Promise.all` over N inferences runs them one after another, for any N. - **`node:sqlite` reads are synchronous** by design, because the resolution ladder is a sync interface (see `packages/sqlite/AGENTS.md`). The resolve half of a geocode also blocks. The measured scale stays between 1.00x and 1.02x at every concurrency level. Contention would produce a declining curve. A flat line means that no work overlapped. `POST /v1/batch` therefore processes rows one at a time and has no concurrency setting. The `MAILWOMAN_BATCH_CONCURRENCY` setting it used to have (default 8) gave the same throughput to three digits at 1 and at 16, and was removed on 2026-07-16. The same change works in Python, where `intra_op=1` plus 16 threads gives 1.64x, because Python's ORT binding releases the GIL during a run. ## Batched inference The obvious counterexample is [deepparse](https://deepparse.org/). It parses at 3.1 ms/addr batched against 32.5 ms sequential, a 10x improvement. That 10x comes from amortizing per-call Python and torch overhead. Mailwoman doesn't have that overhead. Our sequential path (~300 addr/s) already matches deepparse's batched throughput (320 addr/s), and its latency is about 9.9x lower than deepparse's sequential path (3.29 ms against 32.5 ms). These results were measured on the shipped int8 graph, re-exported so that it could accept a batch: | batch | ms/addr | addr/s | scaling | | ----: | ------: | -----: | ------: | | 1 | 3.29 | 304.1 | 1.00x | | 4 | 2.93 | 341.7 | 1.12x | | 8 | 3.30 | 303.5 | 1.00x | | 32 | 4.64 | 215.6 | 0.71x | | 64 | 5.33 | 187.7 | 0.62x | Throughput peaks at 1.12x and then declines. fp32 behaves the same way (1.24x at B=4). Higher arithmetic intensity helps when cores sit idle waiting on memory. Here ONNX Runtime already keeps about eight cores busy on one batch=1 inference. Above B=8, the working set no longer fits, and throughput drops. **On CPU, do not build a batching path.** On GPU or WebGPU the arithmetic intensity differs, and batching could plausibly help, but it is unmeasured. ## The ONNX export's batch dimension The exporter measured here was the Python trainer's `export_onnx.py` module. It moved to `export/onnx.py` on 2026-09-12 (`0879ce6ab`) and was deleted with the rest of the Python trainer on 2026-11-01 (`f5cb99a5f`). Read the measured version with `git show 0879ce6ab^:corpus-python/src/mailwoman_train/export_onnx.py`. The exporter is now the Rust crate `packages/trainer/crates/trainer-export`. The Python exporter requested a dynamic batch dimension on all eight inputs, and the export silently ignored that request. The graph advertised `['batch', 'sequence']` on every input while its outputs were fixed at `[1, 'sequence', 33]`, and any batch above 1 failed inside an attention reshape: ``` Input shape:{64,4,1152}, requested shape:{64,1,3,384} ``` That `1` is the batch dimension, traced in as a literal. The cause is **`torch.export`'s 0/1 specialization**. `torch.export` always specializes a dimension of size 0 or 1 to a constant, even when `dynamic_shapes` marks it dynamic. The export traced with batch=1 example inputs, so it discarded the dynamic request but still labeled the input `'batch'`. The metadata was therefore wrong. A batch=2 trace fixes it: ``` dummy_batch=1 logits_out=[1, 'sequence', 33] B=4:FAIL dummy_batch=2 logits_out=['batch', 'sequence', 33] B=4:OK B=32:OK ``` `export_to_onnx` therefore gained a `dummy_batch` parameter for the probe. It defaulted to 1 and no caller in the tree passed another value, so the shipped artifact stayed the batch=1 graph. The Rust exporter declares the same shapes as that graph: dimension 0 of every output is the literal `1`, although its computation doesn't specialize the batch (`packages/trainer/crates/trainer-export/src/export.rs`). No batching feature is planned. Do not try to reproduce the specialization with a small model. A minimal reshape repro exports correctly at batch=1 on torch 2.13. The failure comes from the transformers attention internals, so only the real checkpoint shows it. ## Worker threads [`geocodeStream`](https://github.com/sister-software/mailwoman/blob/main/packages/mailwoman/lib/geocode/batch/stream.ts) moves work across a thread boundary. It is an async iterator over a `spliterator` worker pool. Each worker builds its own classifier and lookups, and results are yielded in completion order. Expect a modest gain. The geocoding path is memory- and I/O-bound on a shared multi-gigabyte database. A measured NPPES sweep peaked at **two workers (~1.4x)** and degraded after that: four workers matched the baseline, and six gave no gain. Each worker also pays for its own 38 MB session and its own open database. Measure the worker count on your own data and machine instead of defaulting to `availableParallelism()`. Parse-only threading has no database and no contention, so it should scale further than geocoding. That scaling is unmeasured. In Python, `intra_op=2` with 8 threads reached 1.57x. That result suggests the likely shape of the curve, but it isn't a figure to quote. ## Before you re-measure Avoid two mistakes, both of which produced a wrong answer during the original sweep: - **Warm up, and repeat.** A single cold run showed concurrency at 1.19x on the geocode path and nearly led to keeping the concurrency setting. Repeated runs showed no trend, and `c=1` beat `c=8` half the time. The spread across identical configs is ~13%, wider than most effects under investigation. - **Instrument the real runner.** The forward-pass split needs `classifier.cfg.runner`. The wrong field reports 0 ms and 0%, which looks like a measurement but means the code measured no work. This is the same class of bug as [the meaning of zero](./the-meaning-of-zero.mdx). The probes were scratchpad scripts and were never committed: `batch-export-probe.py`, `ort-threads-probe.mjs`, `parse-profile.run.ts`, `parse-concurrency.run.ts`, `parse-cpu.run.ts`. `git log --all` finds none of the five on any ref, so a re-measurement has to write them again. ## CLI cold start versus a warm stream Measure the installed executable directly when profiling Mailwoman, because `npx` adds package-runner startup time that's not part of `mw` itself. `hyperfine` repeats whole-process launches (process-cold, normally filesystem-cache-warm): ```sh hyperfine --warmup 0 --runs 10 \ './node_modules/.bin/mw geocode "3215 SE Clinton St. Portland OR" >/dev/null' ``` Add `--timing` to break down the wall time. Diagnostics go to stderr, so the result on stdout stays valid JSON: ```sh ./node_modules/.bin/mw geocode --timing \ "3215 SE Clinton St. Portland OR" >/dev/null ``` The report separates the launcher/CLI import graph, session import, one-time session initialization (weights, resolver, backends, optional providers, priors), and the warm parse/resolve phases. The launcher and router import only the selected command. Root and group help list command paths without importing their implementations, and detailed command help imports only that command and the help renderer. A large CLI-import time therefore comes from the selected command's own static dependency graph. To measure persistent sequential throughput, feed one address per line. The command initializes once and emits one compact JSON object per line: ```sh /usr/bin/time -v sh -c \ './node_modules/.bin/mw geocode --stdin < addresses.txt > /dev/null' pv -l addresses.txt | ./node_modules/.bin/mw geocode --stdin | pv -l >/dev/null ``` To compare the two directly, run both under `hyperfine`. Repeated processes pay the cold start for every address, while stdin pays it once: ```sh hyperfine --runs 5 \ 'while IFS= read -r address; do ./node_modules/.bin/mw geocode "$address"; done < addresses.txt >/dev/null' \ './node_modules/.bin/mw geocode --stdin < addresses.txt >/dev/null' ``` `xargs -P` measures capacity under concurrency. That's a different quantity from warm sequential throughput.