Expand description
LRU width cache for efficient text measurement.
Text width calculation is a hot path (called every render frame). This cache stores computed widths to avoid redundant Unicode width calculations for repeated strings.
§VS16 Policy and Caching
Cache keys are the grapheme string itself. The VS16 width policy
(controlled by FTUI_EMOJI_VS16_WIDTH) is global and read once at
startup via OnceLock in ftui_core::text_width. Changing the env
var mid-process has no effect on cached or future lookups.
§Example
use ftui_text::WidthCache;
let mut cache = WidthCache::new(1000);
// First call computes width
let width = cache.get_or_compute("Hello, world!");
assert_eq!(width, 13);
// Second call hits cache
let width2 = cache.get_or_compute("Hello, world!");
assert_eq!(width2, 13);
// Check stats
let stats = cache.stats();
assert_eq!(stats.hits, 1);
assert_eq!(stats.misses, 1);Structs§
- Cache
Stats - Statistics about cache performance.
- Count
MinSketch - Count-Min Sketch for approximate frequency estimation.
- Doorkeeper
- 1-bit Bloom filter used as a doorkeeper to filter one-hit wonders.
- S3Fifo
Width Cache - Width cache backed by S3-FIFO eviction (bd-l6yba.2).
- Tiny
LfuWidth Cache - Width cache using W-TinyLFU admission policy.
- Width
Cache - LRU cache for text width measurements.
Constants§
- DEFAULT_
CACHE_ CAPACITY - Default cache capacity.
Functions§
- fingerprint_
hash - Compute a secondary fingerprint hash for collision guard.
- tinylfu_
admit - Evaluate the TinyLFU admission rule.