Skip to main content

intern_key

Function intern_key 

Source
pub fn intern_key(key: &str) -> HarnStr
Expand description

Intern a dict key into a shared HarnStr.

Agent workloads are dict-heavy and the same field names (role, content, arguments, …) recur across thousands of message/JSON dicts. Interning short keys lets every occurrence share one allocation (a refcount bump on reuse) instead of allocating a fresh string per key. The table is bounded — only keys up to [MAX_INTERNED_KEY_LEN] bytes are eligible, and once [MAX_INTERNED_KEYS] distinct keys are cached no new entries are added — so adversarial or high-cardinality keys (UUIDs, user input) fall back to a plain allocation and can never grow the table without bound.