Skip to main content

Stats

Struct Stats 

Source
pub struct Stats {
    pub computed: u64,
    pub validated: u64,
    pub hits: u64,
}
Expand description

A snapshot of how a Database resolved its queries.

Incremental compilation is only worth its complexity if it actually avoids work, and the only way to know it does is to count. Every derived query resolution takes exactly one of three paths, and Stats counts each:

  • computed — the query ran its compute function. This is the expensive path: a cache miss, or a dependency that genuinely changed and forced a recomputation.
  • validated — the query was stale (something changed since it was last checked) but re-examining its dependencies proved none of them actually changed its inputs, so the cached value was reused without recomputing. This is early cutoff, the property that makes the engine fast: a change that does not alter a query’s inputs does not recompute it.
  • hits — the query was already verified at the current revision and returned immediately, without even checking dependencies.

The counters are cumulative over the life of the database and only ever increase. Snapshot them with Database::stats before and after an operation to measure exactly what that operation cost.

§Examples

After a run, most re-queries of an unchanged graph are hits, and a targeted input change recomputes only what depends on it:

use query_lang::{Database, System, QueryError};

struct Doubler;
impl System for Doubler {
    type Key = u32;
    type Value = u32;
    fn compute(&self, db: &Database<Self>, key: &u32) -> Result<u32, QueryError> {
        Ok(db.get(&(key + 100))? * 2) // reads input (key + 100), doubles it
    }
}

let mut db = Database::new(Doubler);
db.set(101, 5);

assert_eq!(db.get(&1)?, 10);
assert_eq!(db.stats().computed, 1); // first resolution computes

assert_eq!(db.get(&1)?, 10);
assert_eq!(db.stats().hits, 1);     // second is a free hit

Fields§

§computed: u64

The number of times a query ran its compute function (a real cache miss or a forced recomputation).

§validated: u64

The number of times a stale query was revalidated and its cached value reused because no dependency actually changed its inputs (early cutoff).

§hits: u64

The number of times a query was already current and returned immediately.

Implementations§

Source§

impl Stats

Source

pub const fn total(self) -> u64

The total number of derived-query resolutions across all three paths.

This counts work the engine was asked to do; the ratio of computed to this total is how much of that work actually cost a recomputation.

§Examples
use query_lang::Stats;

let s = Stats { computed: 2, validated: 3, hits: 5 };
assert_eq!(s.total(), 10);

Trait Implementations§

Source§

impl Clone for Stats

Source§

fn clone(&self) -> Stats

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Stats

Source§

impl Debug for Stats

Source§

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

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

impl Default for Stats

Source§

fn default() -> Stats

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

impl Display for Stats

Source§

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

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

impl Eq for Stats

Source§

impl PartialEq for Stats

Source§

fn eq(&self, other: &Stats) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Stats

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Stats

Auto Trait Implementations§

§

impl Freeze for Stats

§

impl RefUnwindSafe for Stats

§

impl Send for Stats

§

impl Sync for Stats

§

impl Unpin for Stats

§

impl UnsafeUnpin for Stats

§

impl UnwindSafe for Stats

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.