Struct soroban_env_host::budget::CostModel
source · pub struct CostModel {
pub const_param: u64,
pub log_param: u64,
pub log_base_param: u64,
pub lin_param: u64,
pub quad_param: u64,
}
Expand description
We provide a general “cost model” object that evaluates a general expression:
f(x) = a + blog_i(x) + cx + d*(x^2)
Where a, b, c, d, and i are all “fixed” parameters at construction time (extracted from an on-chain cost schedule, so technically not totally fixed) and x is some abstract input variable – say, event counts or object sizes – provided at runtime.
The log base i is also rounded-up to its nearest power of 2, since we implement that term using bit count instructions.
The same CostModel type (applied to different parameters and variables) is used for calculating memory as well as CPU time. We hope this expression is capable of modeling any of the costs we want to measure at runtime.
The parameters for a CostModel are calibrated empirically. See this crate’s benchmarks for more details.
Fields§
§const_param: u64
§log_param: u64
§log_base_param: u64
§lin_param: u64
§quad_param: u64
Implementations§
Trait Implementations§
source§impl Ord for CostModel
impl Ord for CostModel
source§impl PartialEq<CostModel> for CostModel
impl PartialEq<CostModel> for CostModel
source§impl PartialOrd<CostModel> for CostModel
impl PartialOrd<CostModel> for CostModel
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for CostModel
impl StructuralEq for CostModel
impl StructuralPartialEq for CostModel
Auto Trait Implementations§
impl RefUnwindSafe for CostModel
impl Send for CostModel
impl Sync for CostModel
impl Unpin for CostModel
impl UnwindSafe for CostModel
Blanket Implementations§
source§impl<T, U, V, E, C> Compare<(T, U, V)> for Cwhere
C: Compare<T, Error = E, Error = E, Error = E> + Compare<U> + Compare<V>,
impl<T, U, V, E, C> Compare<(T, U, V)> for Cwhere
C: Compare<T, Error = E, Error = E, Error = E> + Compare<U> + Compare<V>,
source§impl<T, U, E, C> Compare<(T, U)> for Cwhere
C: Compare<T, Error = E, Error = E> + Compare<U>,
impl<T, U, E, C> Compare<(T, U)> for Cwhere
C: Compare<T, Error = E, Error = E> + Compare<U>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.