1 stable release
Uses new Rust 2024
| new 1.1.0 | Feb 11, 2026 |
|---|
#623 in Text processing
35KB
763 lines
uvie
A really fast Vietnamese input method engine in Rust.
Why it is "ultra fast"
Benchmarks (cargo bench) usually put uvie in the ns → low µs range per sequence.
Why it’s fast:
- Minimal allocation (fixed small buffers; optional
heaplessmode) - Single-pass transforms (no extra scans / passes)
- Small fixed-capacity buffers (cache-friendly, predictable)
- CPU-friendly control flow: reduce unpredictable branches to lower branch-misprediction stalls
- Branch-reduction techniques: table lookups, bitmasks, and “branchless” selection patterns instead of large
match/ifladders - O(1) query-time operations for the core lookup/transform steps
- Optimized for tight loops.
Features
- Supports Telex and VNI input methods.
- Easy to use: simple API, no dependencies, easy to embed, extensible.
- Default (
std): normal RustStringbuffers. heapless: uses fixed-capacityheapless::Stringbuffers (no heap allocation from the engine itself).- Can be built in a heapless-friendly configuration for embedded devices, low-resources environments.
Note: in
heaplessmode, if internal buffers overflow, output may be truncated.
How to use
Add it to your project:
[dependencies]
uvie = { path = "../uvie" }
Telex:
use uvie::{InputMethod, UltraFastViEngine};
let mut e = UltraFastViEngine::new();
e.set_input_method(InputMethod::Telex);
for ch in "phoos".chars() {
e.feed(ch);
}
assert_eq!(e.feed(' '), "phố ");
VNI:
use uvie::{InputMethod, UltraFastViEngine};
let mut e = UltraFastViEngine::new();
e.set_input_method(InputMethod::Vni);
for ch in "viet65".chars() {
e.feed(ch);
}
assert_eq!(e.feed(' '), "việt ");
Embedded/heapless check:
cargo check --no-default-features --features heapless
CLI demo
The repository contains a small interactive CLI (enabled only with std).
cargo run -- --mode telex
cargo run -- --mode vni
Controls:
- Press
Enterto flush - Press
Ctrl+Cto exit
Benchmarks (uvie vs vi)
Benchmarks use criterion.
cargo bench
cargo bench runs benchmarks in the bench profile (release target).
The benchmark file is in benches/perf.rs and currently benchmarks:
uvie_telexuvie_vni
It also includes direct comparisons against the vi crate:
compare_telex/*compare_vni/*
Fairness notes
uvieis benchmarked by reusing a singleUltraFastViEngineinstance per benchmark and callingclear()between iterations.viis benchmarked viavi::methods::transform_buffer, reusing a singleStringoutput buffer per benchmark iteration.
Results
The exact numbers depend on CPU/OS, but the ratio is stable.
Sample run (Apple Silicon, cargo bench):
| Case | Telex speedup (vi / uvie) | VNI speedup (vi / uvie) |
|---|---|---|
| simple | ~16x | ~18x |
| sentence | ~15x | ~14x |
| mixed | ~17x | ~11x |
| uow / uow_like | ~15x | n/a |
| cluster | ~15x | ~15x |
| ui | ~22x | ~11x |
See more details at online report
Embedded / heapless build
To build the library without default std and with heapless buffers:
cargo check --no-default-features --features heapless
Dependencies
~165KB