wasmtime

Enum Collector

Source
#[non_exhaustive]
pub enum Collector { Auto, DeferredReferenceCounting, Null, }
Expand description

Possible garbage collector implementations for Wasm.

This is used as an argument to the Config::collector method.

The properties of Wasmtime’s available collectors are summarized in the following table:

CollectorCollects Garbage1Latency2Throughput3Allocation Speed4Heap Utilization5
DeferredReferenceCountingYes, but not cycles🙂🙁😐😐
NullNo🙂🙂🙂🙂

  1. Whether or not the collector is capable of collecting garbage and cyclic garbage. 

  2. How long the Wasm program is paused during garbage collections. Shorter is better. In general, better latency implies worse throughput and vice versa. 

  3. How fast the Wasm program runs when using this collector. Roughly equivalent to the number of Wasm instructions executed per second. Faster is better. In general, better throughput implies worse latency and vice versa. 

  4. How fast can individual objects be allocated? 

  5. How many objects can the collector fit into N bytes of memory? That is, how much space for bookkeeping and metadata does this collector require? Less space taken up by metadata means more space for additional objects. Reference counts are larger than mark bits and free lists are larger than bump pointers, for example. 

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Auto

An indicator that the garbage collector should be automatically selected.

This is generally what you want for most projects and indicates that the wasmtime crate itself should make the decision about what the best collector for a wasm module is.

Currently this always defaults to the deferred reference-counting collector, but the default value may change over time.

§

DeferredReferenceCounting

The deferred reference-counting collector.

A reference-counting collector, generally trading improved latency for worsened throughput. However, to avoid the largest overheads of reference counting, it avoids manipulating reference counts for Wasm objects on the stack. Instead, it will hold a reference count for an over-approximation of all objects that are currently on the stack, trace the stack during collection to find the precise set of on-stack roots, and decrement the reference count of any object that was in the over-approximation but not the precise set. This improves throughtput, compared to “pure” reference counting, by performing many fewer refcount-increment and -decrement operations. The cost is the increased latency associated with tracing the stack.

This collector cannot currently collect cycles; they will leak until the GC heap’s store is dropped.

§

Null

The null collector.

This collector does not actually collect any garbage. It simply allocates objects until it runs out of memory, at which point further objects allocation attempts will trap.

This collector is useful for incredibly short-running Wasm instances where additionally you would rather halt an over-allocating Wasm program than spend time collecting its garbage to allow it to keep running. It is also useful for measuring the overheads associated with other collectors, as this collector imposes as close to zero throughput and latency overhead as possible.

Trait Implementations§

Source§

impl Clone for Collector

Source§

fn clone(&self) -> Collector

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Collector

Source§

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

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

impl Default for Collector

Source§

fn default() -> Collector

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

impl PartialEq for Collector

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Collector

Source§

impl Eq for Collector

Source§

impl StructuralPartialEq for Collector

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

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

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

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

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.