Module mem_optimize

Module mem_optimize 

Source
Expand description

Advanced memory optimizations for prax-query.

This module provides high-performance memory management utilities:

  • Enhanced string interning: Global and scoped interning with auto-intern for identifiers
  • Typed arena allocators: Efficient arena allocation for query builder chains
  • Lazy schema parsing: On-demand parsing of introspection results

§Performance Gains

OptimizationFeatureMemory Reduction
String interningAll query builders20-30%
Arena allocationHigh-throughput queries15-25%
Lazy parsingIntrospection40-50%

§Example

use prax_query::mem_optimize::{
    interning::{GlobalInterner, ScopedInterner},
    arena::{QueryArena, ArenaAllocated},
    lazy::{LazySchema, LazyColumn},
};

// Global string interning for identifiers
let field = GlobalInterner::get().intern("user_id");

// Scoped arena for query building
let arena = QueryArena::new();
arena.scope(|scope| {
    let filter = scope.alloc_filter(/* ... */);
    let query = scope.build_query(filter);
    query.to_sql() // Returns owned SQL, arena freed on scope exit
});

// Lazy schema parsing
let schema = LazySchema::from_raw(raw_data);
// Columns only parsed when accessed
let name = schema.get_table("users")?.get_column("name")?.db_type();

Re-exports§

pub use arena::ArenaScope;
pub use arena::QueryArena;
pub use arena::ScopedFilter;
pub use arena::ScopedQuery;
pub use arena::ScopedValue;
pub use interning::GlobalInterner;
pub use interning::InternedStr;
pub use interning::ScopedInterner;
pub use interning::IdentifierCache;
pub use lazy::LazyColumn;
pub use lazy::LazyForeignKey;
pub use lazy::LazyIndex;
pub use lazy::LazySchema;
pub use lazy::LazyTable;
pub use lazy::ParseOnDemand;

Modules§

arena
Typed arena allocation for query builder chains.
interning
Enhanced string interning for efficient identifier storage.
lazy
Lazy schema parsing for on-demand introspection.