Skip to main content

vibe_coding_tracker/
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/// Pre-allocation capacity hints to minimize reallocation overhead.
14pub mod capacity {
15    /// Expected number of AI models per conversation session.
16    pub const MODELS_PER_SESSION: usize = 3;
17
18    /// Expected number of unique dates in usage tracking.
19    pub const DATES_IN_USAGE: usize = 30;
20
21    /// Expected number of unique models in batch analysis.
22    pub const MODEL_COMBINATIONS: usize = 20;
23
24    /// Expected number of session files per directory.
25    pub const SESSION_FILES: usize = 50;
26
27    /// Maximum number of parsed files held in the LRU file cache.
28    ///
29    /// Deliberately small (reduced from 15 to 5) to bound RSS in TUI mode,
30    /// where the cache is refreshed repeatedly.
31    pub const FILE_CACHE_SIZE: usize = 5;
32
33    /// Expected number of token fields per usage entry.
34    pub const TOKEN_FIELDS: usize = 8;
35}
36
37/// Buffer sizes for I/O operations.
38pub mod buffer {
39    /// File read buffer size in bytes (128 KiB, tuned for throughput).
40    pub const FILE_READ_BUFFER: usize = 128 * 1024;
41
42    /// Estimated average JSONL line size in bytes, used to pre-size line
43    /// capacity when reading sessions.
44    pub const AVG_JSONL_LINE_SIZE: usize = 500;
45}
46
47/// TUI refresh cadences.
48pub mod refresh {
49    /// Lightweight CPU/memory sampling + redraw cadence for the summary bar,
50    /// decoupled from the heavier session-aggregation refresh. Reading our own
51    /// process stats and repainting cached rows is nearly free, so this can run
52    /// far more often than the data refresh without noticeable overhead.
53    pub const METRICS_REFRESH_MS: u64 = 2000;
54}