vct_core/constants.rs
1//! Compile-time sizing knobs: pre-allocation capacities and I/O buffer sizes.
2//!
3//! These are best-effort hints to size collections and buffers up front so
4//! the hot paths reallocate less; they are not hard limits except where noted
5//! (e.g. [`capacity::FILE_CACHE_SIZE`], which bounds the LRU).
6
7/// Hash map backed by `ahash` for fast, non-cryptographic hashing.
8///
9/// Used in place of `std::collections::HashMap` on hot aggregation paths; the
10/// keys here are not attacker-controlled, so DoS resistance is not required.
11pub type FastHashMap<K, V> = ahash::AHashMap<K, V>;
12
13/// Hash set backed by `ahash` for fast, non-cryptographic hashing.
14///
15/// Used in place of `std::collections::HashSet` on the incremental scan path,
16/// where the keys are process-local (not attacker-controlled).
17pub type FastHashSet<T> = ahash::AHashSet<T>;
18
19/// Pre-allocation capacity hints to minimize reallocation overhead.
20pub mod capacity {
21 /// Expected number of AI models per conversation session.
22 pub const MODELS_PER_SESSION: usize = 3;
23
24 /// Expected number of unique dates in usage tracking.
25 pub const DATES_IN_USAGE: usize = 30;
26
27 /// Expected number of unique models in batch analysis.
28 pub const MODEL_COMBINATIONS: usize = 20;
29
30 /// Expected number of session files per directory.
31 pub const SESSION_FILES: usize = 50;
32
33 /// Maximum number of parsed files held in the LRU file cache.
34 ///
35 /// Deliberately small (reduced from 15 to 5) to bound RSS in TUI mode,
36 /// where the cache is refreshed repeatedly.
37 pub const FILE_CACHE_SIZE: usize = 5;
38
39 /// Expected number of token fields per usage entry.
40 pub const TOKEN_FIELDS: usize = 8;
41}
42
43/// Buffer sizes for I/O operations.
44pub mod buffer {
45 /// File read buffer size in bytes (128 KiB, tuned for throughput).
46 pub const FILE_READ_BUFFER: usize = 128 * 1024;
47
48 /// Estimated average JSONL line size in bytes, used to pre-size line
49 /// capacity when reading sessions.
50 pub const AVG_JSONL_LINE_SIZE: usize = 500;
51}
52
53/// TUI refresh cadences.
54pub mod refresh {
55 /// Lightweight CPU/memory sampling + redraw cadence for the summary bar,
56 /// decoupled from the heavier session-aggregation refresh. Reading our own
57 /// process stats and repainting cached rows is nearly free, so this can run
58 /// far more often than the data refresh without noticeable overhead.
59 pub const METRICS_REFRESH_MS: u64 = 2000;
60}