Expand description
String interning and caching. String interning cache for reducing allocations
This module provides thread-local string interning to reduce memory allocations for frequently repeated strings like field names and type names.
§Performance Impact
For documents with repeated schemas:
- 50-70% reduction in field name allocations
- 30-40% memory reduction
- <2% overhead for cache lookups
§Example
use hedl_json::string_cache::{intern_string, string_cache_stats};
// Strings are automatically interned
let s1 = intern_string("field_name");
let s2 = intern_string("field_name");
// Same Arc pointer (zero allocation on second call)
assert!(std::sync::Arc::ptr_eq(&s1, &s2));
// Check cache statistics
let stats = string_cache_stats();
println!("Cache hit rate: {:.1}%", stats.hit_rate() * 100.0);Structs§
- Cache
Stats - Statistics about the string cache
Functions§
- clear_
string_ cache - Clear the string cache for the current thread
- intern_
string - Intern a string, returning an
Arc<str> - string_
cache_ stats - Get statistics about the current thread’s string cache