Skip to main content

Pacer

Enum Pacer 

Source
pub enum Pacer {
    Doubling,
    Bounded {
        ceiling: NonZeroUsize,
        live_factor: NonZeroUsize,
    },
}
Expand description

How Heap::collect_inner chooses the next paced collection threshold.

Fixed at construction (there is no Cell): a collector that could change its own schedule mid-run would make “when does this program collect” a function of history rather than of the heap it was built with, and every pacing test would become order-dependent.

Both arms exist in one binary so the A/B behind Pacer::from_env is a single build rather than two, and the branch is taken once per collection — never on the allocation path.

Variants§

§

Doubling

ADR-011’s original heuristic: max(previous × 2, INITIAL), unbounded. Retained as the measured-against arm; see ADR-112.

§

Bounded

max(min(previous × 2, ceiling), live × live_factor, INITIAL).

Constructible only through Pacer::bounded, which clamps both fields, so “a ceiling below the first threshold” and “zero headroom” have no spelling.

Fields

§ceiling: NonZeroUsize

The largest the ratchet term may reach. It does not bound the whole expression; see Pacer::next_threshold.

§live_factor: NonZeroUsize

The multiple of the measured live set the threshold must leave room for, whatever the ceiling says.

Implementations§

Source§

impl Pacer

Source

pub const DEFAULT: Pacer

What a Heap paces with when nothing says otherwise.

One named constant rather than a literal at the sites that need it, so “what does this workspace’s collector actually do” has exactly one answer to read.

Source

pub const fn bounded(ceiling: usize, live_factor: usize) -> Pacer

The bounded rule, with both parameters clamped into the range in which they mean something.

A ceiling below INITIAL_COLLECT_THRESHOLD is raised to it: the first threshold is already INITIAL, so a lower ceiling would describe a heap that had exceeded its own bound before its first allocation. A live_factor of zero is raised to one: it would delete the mandatory term, which is the whole anti-thrash half of the rule. Neither clamp is a convenience — they are why the two illegal states have no spelling (a_bounded_pacer_cannot_be_built_with_a_ceiling_below_the_first_threshold).

Source

pub fn next_threshold(self, previous: usize, live: usize) -> usize

The threshold the collection that just finished sets for the next one.

previous is the threshold that was in force; live is the block bytes Heap::sweep just measured.

The ceiling clamps the ratchet term only, and never the whole expression. min(ceiling) applied to the result would make a program whose live set legitimately exceeds the ceiling collect on essentially every allocation, which is a thrash bug and not a memory bound. The ceiling bounds speculative growth — the part of the threshold that is a guess about the future; live × live_factor is mandatory headroom, a statement about the present, and it must be allowed to exceed the ceiling. ADR-112 decision 2 is the argument, and a_bounded_pacer_gives_a_large_live_set_its_headroom is the test that fails if someone folds the ceiling over the max.

The rule is monotonically non-decreasing up to the ceiling — once previous >= ceiling, min(previous × 2, ceiling) == ceiling — so no separate growth floor is needed: the ratchet-to-ceiling is the floor, and it is what keeps a shrinking live set from dragging the threshold back down toward it (a_shrinking_live_set_does_not_lower_the_threshold_below_the_ceiling).

Trait Implementations§

Source§

impl Clone for Pacer

Source§

fn clone(&self) -> Pacer

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 Pacer

Source§

impl Debug for Pacer

Source§

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

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

impl Eq for Pacer

Source§

impl PartialEq for Pacer

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Pacer

Auto Trait Implementations§

§

impl Freeze for Pacer

§

impl RefUnwindSafe for Pacer

§

impl Send for Pacer

§

impl Sync for Pacer

§

impl Unpin for Pacer

§

impl UnsafeUnpin for Pacer

§

impl UnwindSafe for Pacer

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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, 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.