Skip to content

How Verbora uses Rust

Verbora is fast for an unglamorous reason: it does not allocate much. The algorithms are the standard ones — Levenshtein is Levenshtein, Jaro–Winkler is Jaro–Winkler. What differs is the data that flows through them, and how often it has to be copied.

This section covers the techniques that produce that, where each one surfaces in the API, and what it means for the code you write.

The techniques, and where to find them

TechniqueWhere it shows up in the APIPage
BorrowingFourteen tokenizers yield &str slices of your inputZero-copy
CowFour of six normalizers; all 17 ja::converters; Stemmer::stem; three tokenizersZero-copy
Lazy iteratorstokens(), ngrams_iter(), iter_keys_with_prefix()Iterator vs _into
Caller-owned bufferstokenize_into(), pluralize_into(), stem_into()Buffer reuse
Choosing the smallest working setLevenshtein's bit-vector / row / matrix modesCache locality
Struct-of-arraysThe Levenshtein search matrixCache locality
Flat arenasTrie's Vec<Node> addressed by u32Cache locality
Inline small collectionsSmallVec children per trie nodeCache locality
Stack buffers for small inputsJaro–Winkler's match flagsAllocation
Cheaper hash keysDice hashes (u16, u16) instead of a String per bigramAllocation
Exact fast pathsASCII &[u8] vs Vec<u16> promotion in distance and phoneticsZero-copy
Monomorphised predicatesCharClass as a zero-sized type, so each tokenizer's scan inlinesCache locality

Read these in order

How to read the numbers here

Timings are measured; allocation counts are not. Published timings come from the benchmark pages, and today they cover verbora-distance. Criterion benchmarks for tokenizers, phonetics, n-grams, normalizers, inflectors and the trie exist in-tree (crates/*/benches/) but their tables are not published yet, so this section says "fewer allocations" rather than quoting a speed figure for those subsystems. Where a page describes allocation behaviour it describes what the code does, read from the source — allocation counting and peak-RSS instrumentation are not in the repository.

Released under the MIT License.