# Catalog on 100,000 messages

## Round 4 cross-target measurement

On 2026-12-03, each release backend ran in eight fresh processes on Windows 11 x64 (10.0.26100), Intel Core i9-13980HX, Moon/moonrun 0.1.20261126, moonc v1.0.0-rc1+3c0520448, Python 3.13.5 and psutil 5.9.0. All three used the round-2 worker and the same 4,850,162-byte MO with 50,000 singular and 50,000 plural messages. Construction measures only `Catalog::from_bytes` after reading the input. Each query median comes from eight per-process averages over 200,000 checked lookups of that kind.

| Median | native | wasm | wasm-gc |
| --- | ---: | ---: | ---: |
| Catalog construction (ms) | 143.11 | 133.86 | 89.23 |
| gettext on singular key (ns/query) | 1,039.48 | 869.96 | 812.14 |
| gettext on plural key (ns/query) | 1,154.92 | 910.23 | 1,169.99 |
| Missing key, common prefix (ns/query) | 279.92 | 308.60 | 276.28 |
| Process peak working set (MiB) | 43.85 | 63.11 | 199.26 |

```sh
python scripts/benchmark.py --target native --target wasm --target wasm-gc --runs 8
```

The script reverses the launch order on alternate rounds and starts each process without a separate warm-up. Native runs as a standalone executable. Both Wasm targets run under moonrun. Native construction ranged from 92.61 to 165.95 ms in this session. These host-dependent times are a comparison within the session. The earlier optimization and Wasm measurements below retain their original values.

## Earlier native optimization

Windows x64, Intel Core i9-13980HX, Moon 0.1.20261126, release-native. The deterministic little-endian MO is 4,850,162 bytes with one ASCII header, 50,000 singular entries and 50,000 three-slot plural entries. Each run starts a fresh process. The build timer starts after reading the MO and ends when Catalog returns. For each query kind the worker preallocates 50,000 distinct keys, traverses a permutation four times, checks the returned length checksum and divides elapsed time by 200,000.

| Median of eight runs per binary, alternating launch order | Before | After |
| --- | ---: | ---: |
| Catalog construction (ms) | 91.4466 | 92.4013 |
| gettext on singular key (ns/query) | 723.95 | 723.63 |
| gettext on plural key (ns/query) | 1195.29 | 834.09 |
| Missing key, common prefix (ns/query) | 221.90 | 215.72 |
| Process peak working set (MiB) | 43.85 | 43.84 |

The original ordinary lookup re-evaluated the same plural expression at n=1 for every plural hit. Construction now selects that translation once and stores a reference alongside the slots. The measured query cost fell by 30.2% on this workload. Checked count-dependent queries still evaluate the caller's count, and ordinary lookup keeps its slot-zero fallback. The index remains the sorted original table with binary search.

Run `python scripts/benchmark.py` with Python and psutil to regenerate the MO and measure the current build in seven fresh processes. psutil is only used by the measurement script. Memory includes the runtime, input buffer, construction temporaries and query key arrays. Windows reports the process high-water mark sampled every 2 ms. On POSIX the script samples resident bytes, so it may miss brief peaks. Timings cover in-process lookups on one host and do not include CLI startup or file I/O.

## Wasm on the same 100,000-message workload

Measured on 2026-12-03 on Windows 11 x64 (10.0.26100), Intel Core i9-13980HX, Moon and moonrun 0.1.20261126 (ccd306a), moonc v1.0.0-rc1+3c0520448, Python 3.13.5 and psutil 5.9.0. Both release artifacts ran directly under moonrun. The benchmark reused the same 4,850,162-byte MO and the same MoonBit worker, key permutation, checksums and timing boundaries as the Native measurements above.

| Median of eight fresh processes per target | wasm | wasm-gc |
| --- | ---: | ---: |
| Catalog construction (ms) | 111.4726 | 80.7428 |
| gettext on singular key (ns/query) | 647.96 | 753.27 |
| gettext on plural key (ns/query) | 715.49 | 712.88 |
| Missing key, common prefix (ns/query) | 226.21 | 175.88 |
| Process peak working set (MiB) | 63.14 | 199.65 |

Run `python scripts/benchmark.py --target wasm --target wasm-gc --runs 8`. The script builds both workers before timing, reverses launch order each round and prints every run followed by medians. Each worker executes 200,000 queries of each kind. There is no separate warm-up. Runtime compilation and garbage collection can affect the timed intervals. The Windows peak includes the entire moonrun process and its runtime allocations. The Native table came from a separate session and measures a standalone process. These timings and memory figures apply to these hosts and tools. Individual construction times ranged from 108.75 to 188.08 ms for wasm and from 79.32 to 127.87 ms for wasm-gc.
