Expand description
Enhanced string interning for efficient identifier storage.
This module provides both global and scoped string interning to minimize memory allocations for repeated field names, table names, and other identifiers.
§Interning Strategies
- Static interning: Compile-time constants for common fields (zero allocation)
- Global interning: Thread-safe, lifetime of program, for repeated identifiers
- Scoped interning: Per-request/query, automatically freed when scope ends
§Performance
- First intern: O(n) allocation + hash lookup
- Subsequent lookups: O(n) hash lookup, no allocation
- Cloning interned string: O(1)
§Example
use prax_query::mem_optimize::interning::{GlobalInterner, InternedStr};
// Get the global interner
let interner = GlobalInterner::get();
// Intern a string
let s1 = interner.intern("user_id");
let s2 = interner.intern("user_id");
// Same memory location
assert!(InternedStr::ptr_eq(&s1, &s2));Structs§
- Global
Interner - Thread-safe global string interner.
- Identifier
Cache - Cache for auto-interning common identifier patterns.
- Interned
Str - An interned string that shares memory with other identical strings.
- Interner
Stats - Statistics for an interner.
- Scoped
Interner - A scoped string interner for temporary use.
Functions§
- get_
interned - Try to get an already-interned string from the global interner.
- intern
- Intern a string using the global interner.
- intern_
component - Intern just a component (table or column name).
- intern_
qualified - Intern a qualified identifier (table.column).