Skip to main content

Module string_cache

Module string_cache 

Source
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§

CacheStats
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