Skip to main content

TrieCache

Struct TrieCache 

Source
pub struct TrieCache { /* private fields */ }
Expand description

A thread-safe, byte-bounded cache of byte-tries keyed by vocabulary fingerprint. Read-mostly after warm-up; once the budget is reached, further tries are built and returned but not retained.

Implementations§

Source§

impl TrieCache

Source

pub fn new() -> Self

An empty cache with the default byte budget and concurrent-build cap.

Source

pub fn with_budget(budget: usize) -> Self

An empty cache with an explicit retained-byte budget.

Source

pub fn with_build_limit(budget: usize, max_concurrent_builds: usize) -> Self

An empty cache with an explicit retained-byte budget and the default build gate.

Source

pub fn with_build_gate( budget: usize, max_concurrent_builds: usize, max_transient_build_bytes: usize, ) -> Self

An empty cache with an explicit retained-byte budget, a concurrent-build count cap, AND a transient-build byte budget (so many large concurrent builds cannot exhaust memory).

Source

pub fn peak_concurrent_builds(&self) -> usize

The peak number of simultaneous distinct-vocabulary builds observed (for tests/telemetry).

Source

pub fn peak_concurrent_build_bytes(&self) -> usize

The peak concurrent transient-build bytes charged (for tests/telemetry).

Source

pub fn get_or_build_byte( &self, vocab: &Vocabulary, ) -> Result<Arc<VocabTrie>, CompileError>

The cached byte-trie for vocab, building and inserting it on a miss. Two vocabularies with equal fingerprints get the same Arc; the trie is built outside the lock, so a rare double

Source

pub fn bind( &self, handle: &VocabularyHandle, ) -> Result<BoundByteTrie, CompileError>

The byte-trie for handle’s vocabulary, wrapped as an opaque BoundByteTrie whose fingerprint is guaranteed (by construction, not by caller honesty) to be handle’s own -

Source

pub fn clear(&self)

Drops every retained trie. Also clears the LRU touch-log, so repeated fill/clear cycles cannot accumulate stale log records indefinitely. Traffic counters (stats()) are NOT reset -

Source

pub fn len(&self) -> usize

The number of retained tries.

Source

pub fn is_empty(&self) -> bool

Whether the cache retains no trie.

Source

pub fn bytes(&self) -> usize

Retained trie bytes. Bounds the CACHE only - a trie an active PyIndex/CompiledArtifact holds its own Arc to stays alive via that reference even if evicted or never cached here.

Source

pub fn stats(&self) -> (u64, u64, u64, u64)

(hits, misses, evictions, oversized_bypasses) since creation - a lifetime traffic total, NOT reset by clear() (which only drops currently-retained content). Single-flight caps

Trait Implementations§

Source§

impl Debug for TrieCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TrieCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.