pub struct PluginCache { /* private fields */ }Expand description
Plugin cache for performance optimization.
§Scope: f64 only
CachedPlugin::plugin is monomorphized to Box<dyn OptimizerPlugin<f64>>
– there is no generic PluginCache<A>. PluginRegistry::create_optimizer::<A>
only consults this cache when A = f64; a call with A = f32 (or any
other Float impl) always goes straight to the factory and never
touches instances, stats.hits, or stats.misses. This is a
deliberate scope limitation, not an oversight: caching f32 instances
too would need either a second, separately-bounded HashMap or an
Any-erased value type, and nothing in this crate currently creates
enough f32 optimizers through the registry to justify that complexity.
§Cache key and correctness
Entries are keyed by plugin name, but a lookup is only a hit when the
caller’s OptimizerConfig also equals the config the cached instance
was built with (CachedPlugin::config). A name-only key would let a
caller requesting e.g. a different learning_rate silently receive an
instance built with someone else’s config – that would be exactly the
kind of fabricated-success this crate’s stub-removal pass exists to
eliminate, so a config mismatch is treated as a miss (the stale entry is
replaced by a freshly created one) rather than returned.
§Eviction
Bounded by RegistryConfig::max_cache_size: inserting past the limit
evicts the least-recently-used entry first. “Recently used” is tracked
with a monotonically increasing u64 sequence number bumped on every
insert and every hit, not a wall-clock timestamp – two cache
operations completing within the same clock tick (common on fast
hardware or under #[test]) would otherwise tie under
SystemTime-based LRU and evict a nondeterministically-chosen entry.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for PluginCache
impl !UnwindSafe for PluginCache
impl Freeze for PluginCache
impl Send for PluginCache
impl Sync for PluginCache
impl Unpin for PluginCache
impl UnsafeUnpin for PluginCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.