crates/icu_messageformat_parser/BENCHMARK.md
This document contains benchmark results for the Rust implementation of the ICU MessageFormat parser.
IMPORTANT: Always use -c opt to enable optimizations. Without it, benchmarks run in debug mode and are 6-8x slower.
# Build and run with optimizations (recommended)
bazel run -c opt //crates/icu_messageformat_parser:parser_bench -- --bench
# Alternative: Build first, then run
bazel build -c opt //crates/icu_messageformat_parser:parser_bench
./bazel-bin/crates/icu_messageformat_parser/parser_bench --bench
The benchmark uses Criterion.rs for statistical analysis of performance.
The benchmarks test parsing performance on four different message complexities:
Benchmark run on: Apple Silicon (M-series)
Date: 2025-12-21
Build mode: -c opt (optimized/release)
| Message Type | Avg Time | Throughput | AST Size |
|---|---|---|---|
| complex_msg | 10.0 µs | 100,394 ops/sec | 3,911 bytes |
| normal_msg | 1.33 µs | 752,517 ops/sec | 608 bytes |
| simple_msg | 172 ns | 5,803,212 ops/sec | 127 bytes |
| string_msg | 118 ns | 8,474,576 ops/sec | 52 bytes |
-c opt, performance is 6-8x slower (fastbuild/debug mode)Optimization #1 & #2: Avoid double character counting + eliminate string allocations (2025-12-21):
match_identifier_at_index() to return both string slice AND character count in a single pass, avoiding the need to count characters twiceComparing with the JavaScript/TypeScript implementation (from packages/icu-messageformat-parser/benchmark/benchmark.ts):
| Message Type | JavaScript (V8) | Rust (opt) | Winner |
|---|---|---|---|
| complex_msg | 58,910 ops/sec | 100,394 ops/sec | Rust +70.4% 🚀 |
| normal_msg | 405,440 ops/sec | 752,517 ops/sec | Rust +85.6% 🚀 |
| simple_msg | 2,592,098 ops/sec | 5,803,212 ops/sec | Rust +123.9% 🚀 |
| string_msg | 4,511,129 ops/sec | 8,474,576 ops/sec | Rust +87.9% 🚀 |
Key takeaways:
The parser is implemented in Rust with:
The benchmark implementation can be found in benches/parser_bench.rs, which uses the Criterion framework for accurate performance measurement with statistical analysis.