Module serialize

Module serialize 

Source
Expand description

Serialization module

Provides model serialization in multiple formats:

  • rkyv: Zero-copy deserialization, fastest loading (recommended for production)
  • bincode: Compact binary format, serde-based
  • trb: Incremental format supporting model updates and crash recovery

§Feature Flags

  • mmap: Enables [MmapTrbReader] for true zero-copy I/O. When enabled, TRB files can be memory-mapped for instant model loading with lazy page faults.

§TRB Reader Comparison

ReaderFeatureI/O ModelLoad TimeMemory
TrbReaderdefaultread() to heapO(model_size)O(model_size)
[MmapTrbReader]mmapmmap (lazy)O(1)O(1) initial

§Example (with mmap feature)

#[cfg(feature = "mmap")]
{
    use treeboost::serialize::MmapTrbReader;

    // Instant load - no heap allocation
    let reader = MmapTrbReader::open("model.trb")?;

    // Option 1: Zero-copy access to archived model
    let archived = reader.archived_model()?;

    // Option 2: Deserialize (still faster than TrbReader due to mmap)
    let model = reader.load_model()?;
}

Re-exports§

pub use rkyv_io::deserialize_universal_model;
pub use rkyv_io::load_model;
pub use rkyv_io::load_universal_model;
pub use rkyv_io::save_model;
pub use rkyv_io::save_universal_model;
pub use rkyv_io::serialize_universal_model;

Modules§

rkyv_io
rkyv-based model serialization

Structs§

TrbHeader
Header metadata stored as JSON at the start of the file
TrbReader
Reader for TRB files
TrbUpdateHeader
Header for an update segment
TrbWriter
Writer for creating and appending to TRB files

Enums§

TrbSegment
A parsed segment from a TRB file
UpdateType
Update types that can be appended to a TRB file

Constants§

FORMAT_VERSION
Current format version
TRB_MAGIC
Magic bytes identifying a TRB file

Functions§

load_model_bincode
Load a model from a bincode file
open_for_append
Open an existing TRB file for appending updates
save_model_bincode
Save a model to a bincode file