Module interning

Module interning 

Source
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

  1. Static interning: Compile-time constants for common fields (zero allocation)
  2. Global interning: Thread-safe, lifetime of program, for repeated identifiers
  3. 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§

GlobalInterner
Thread-safe global string interner.
IdentifierCache
Cache for auto-interning common identifier patterns.
InternedStr
An interned string that shares memory with other identical strings.
InternerStats
Statistics for an interner.
ScopedInterner
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).