Skip to main content

load_mmap

Function load_mmap 

Source
pub fn load_mmap<M: DeserializeOwned>(
    path: impl AsRef<Path>,
    expected_type: ModelType,
) -> Result<M>
Expand description

Load a model using memory-mapped I/O (zero-copy where possible)

Toyota Way Principle: Muda (Waste Elimination) - Eliminates redundant data copies by mapping the file directly into the process address space.

§Performance

  • Cold load: ~4x faster than standard load() for large models
  • Memory: Uses ~1x file size vs ~2x for standard load
  • Syscalls: Reduces brk calls from ~970 to ~50

§Safety

Uses OS-level memory mapping. The file must not be modified while loaded. See bundle-mmap-spec.md Section 4 for safety considerations.

§Example

use aprender::format::{load_mmap, ModelType};

// Load large model efficiently
let model: RandomForest = load_mmap("large_model.apr", ModelType::RandomForest)?;

§Feature Flag

When format-mmap is enabled, uses real OS mmap via memmap2. Otherwise, falls back to standard file I/O (same API, heap-allocated).

§Errors

Returns error on file not found, format error, type mismatch, or checksum failure