x18n
| Target | What ran | Result |
|---|---|---|
packages/core, 9 units, 29 functions |
analyze, bridge, record, diff, bench, shadow, gate | every gate passes; 7,925 recorded cases match; slower than TS through a bridge (report) |
packages/builtins/src/formats/shared/, 7 functions |
same | 3,672/3,672 cases match, 960 of them built from 40 real files of the repository (YAML locales, JSON, Markdown, TS), in LF and CRLF |
| whole repository | analyze | 142 units; start_here now lists only units with bridgeable exports |
Found in the tool, and fixed:
analyzerecommended the format parsers first, but their only exports are plugin factories (properties(): Plugin).analyzenow counts bridgeable exports with the rulesbridgeapplies, and leaves units with none out ofstart_here.- Types imported from workspace packages (
@x18n/core) were not followed, soPluginlooked like data. Type lookup now follows workspace packages to their source. recordcould not run a module importing@x18n/coreat runtime: the package has no build output. The resolve hook now maps workspace packages to their source.- Shaped inputs found a real bug in the
text.tsport (Infinity in a range), then an order dependency on V8's sort with NaN comparators;js::sortnow reproduces V8.
The core, function by function
All 29 functions of x18n's core that can move without an API change were ported with rust-anything:
every gate passes and 7,925 recorded cases match exactly. rust-anything bench then showed the ports
are slower than the TS as called from JS, because the bridge costs more than the work. Full report:
demo/x18n-core. The lesson is built in: measure with bench before
shipping a port.
The search, as a batch
The leaf ports above are measured per call. On x18n's sidebar search (50,000 keys, typed letter
by letter), rust-anything profile showed fuzzyScore at about a quarter of the run, called once per key by
matched, and suggested --batch fuzzyScore:text. The generated FuzzyScoreBatch keeps the
keys in Rust; a FuzzyScoreIndex in port.rs lowercases them to UTF-16 once and keeps a 64-bit
mask of the code units in each key, so most keys that cannot match are skipped unread. Results
are identical to the TS pipeline for every query:
| ms per query | vs TS | |
|---|---|---|
| TS pipeline | 10 | 1x |
| TS with the same narrowing | 4.1-5.4 | 2x |
| Batch, default index (port per item, 4 cores) | 5.1 | 1.7x |
Batch with FuzzyScoreIndex (masks), napi, 4 cores |
1.2 | 7x |
Batch with FuzzyScoreIndex ranking itself, napi, 4 cores |
0.45-0.56 | 18-22x |
| The same, wasm, 1 thread | 0.95 | 11.5x |
The step from 7x to 20x: of the 1.2 ms, 0.4 ms was the benchmark's own Array.from(order, i => keys[i]) (a plain loop costs 0.02 ms). The rest came from letting the index rank by itself:
it rescores only the last query's matches when the new query extends it (a key that does not
match s cannot match se), reads one-letter queries from a table of first positions, scores
ASCII keys as bytes, and orders the whole-number scores with a counting sort. Callgrind showed
library calls (memchr, memcmp) costing more than plain loops on 30-byte keys. Part of the gain
is the algorithm, so the benchmark also runs TS with the same narrowing: Rust is 7-12x faster
than that (wasm 5x).
The same pattern in the other languages: the Rust batch on 4 cores against the original on one thread, identical results and errors. The Go and Java rows are not a fair race; see the correction below.
| Language | Workload | Original (1 thread) | Per-call port vs original | Batch (4 cores) vs original |
|---|---|---|---|---|
| Python | fixture slugify, 20,000 strings |
98 ms | - | 17x |
| Ruby | fixture slugify, 20,000 strings |
110 ms | - | 12.7x |
| Ruby | Shellwords.shellescape, 50,000 mixed values |
88 ms | - | 11.8x |
| Go | fixture Slugify, 50,000 strings |
49 ms | 0.93x | 3.3-4.1x |
| Java | fixture slugify, 50,000 strings |
43 ms | 0.68x | 3.0x |
The Go batch first ran slower than one thread: the port allocates per item and glibc's allocator
serialized the threads inside the Go process. Batch crates now use mimalloc. The shellescape batch
also found a port bug that per-call recording had missed: Ruby symbols (shellescape(:sym)) came
back as their JSON marker. Fixed in the port.
Go and Java then went from 2.5x and 1.7x to 4x and 3x. Inside the batch, half the time was not
the work: results were joined and freed on one thread, Go copied them a second time, and Java
made one JNI call per string through modified UTF-8. String results now go back in bulk, written
on all cores into Go's own buffer or one Java char[]. The other half was the ports: on one
thread the Rust slugify was barely faster than Go's and slower than Java's JIT. Lowering ASCII
without table lookups and without an intermediate string fixed that; Java's port keeps the
final-sigma rule by lowering only the whitespace-separated piece that holds a Σ as a whole.
Per call, the Go port went from 0.73x to 0.93x, the Java one from 0.46x to 0.68x.
Correction (2026-11-19, #110). The Java slugify numbers above do not hold up:
- The port was wrong on some text. Java's
Character.isLetterOrDigittakes letters and decimal digits per UTF-16 unit; the port used Rust'schar::is_alphanumeric, which also takes²,Ⅰ,½, vowel signs such asिand characters beyond U+FFFF.slugify("a²b", 0)gavea²binstead ofa-b. The 50,000 benchmark strings had none of them, and neither did the recording. The port now checks the general category per UTF-16 unit,recordadds those characters to every string trap, and the fixture records 1,596/1,596. - The race was not even. The batch ran on 4 cores against Java's serial loop, the batch was built before the timer, and each side reported its best of 15 calls. With JMH, the same inputs, the same number of workers and the copies inside the timer, the reporter measured the original Java at 9.8 ms and the Rust batch at 24.7 ms on 4 workers, 34.1 ms and 43.0 ms on one (50,000 strings, Windows, Core i5-12450H). The Java original is faster. The Go row was measured the same way and has not been re-run.