Optimizer

Struct Optimizer 

Source
pub struct Optimizer { /* private fields */ }
Expand description

Optimize a Wasm program based on profiling data.

§Example

use winliner::{Optimizer, Profile};

// Create and configure an optimizer.
let mut optimizer = Optimizer::new();
optimizer
    .min_total_calls(100)
    .min_ratio(0.99)?
    .max_inline_depth(5);

// Get the original, uninstrumented Wasm program.
let wasm = std::fs::read("path/to/my.wasm")?;

// Get a profile for our Wasm program from somewhere. Read it from disk,
// record it now in this process, etc...
let profile = Profile::default();

// Run the optimizer with the given profile!
let optimized_wasm = optimizer.optimize(&profile, &wasm)?;

Implementations§

Source§

impl Optimizer

Source

pub fn new() -> Self

Create a new, default optimizer.

Source

pub fn min_total_calls(&mut self, min: u64) -> &mut Self

The minimum number of total calls for a call site before it is considered for winlining.

Source

pub fn min_ratio(&mut self, min: f64) -> Result<&mut Self>

The minimum ratio of all calls at a call site that go to a particular callee before the callee is considered for winlining.

Must be between 0.0 and 1.0.

Source

pub fn max_inline_depth(&mut self, max: usize) -> &mut Self

The maximum inlining depth.

This can help limit code size blowup from duplicating many function bodies during inlining.

Source

pub fn emit_feedback_counters(&mut self, emit: bool) -> &mut Self

Whether to emit feedback counters for how often our speculative inlining guesses were correct or incorrect.

When this option is enabled, we will add two globals for each call site where we winlined a speculative callee:

  1. A counter for how many times we guessed correctly.

  2. A counter for how many times we guessed incorrectly.

You can extract this data using the FeedbackCounters type.

This option is false by default.

Source

pub fn fuel(&mut self, fuel: Option<u32>) -> &mut Self

Set the maximum optimization fuel.

This option is useful for Winliner developers, and unlikely to be useful to anyone else.

Allows bisecting optimization bugs to find which optimization site is buggy.

Source

pub fn optimize(&self, profile: &Profile, wasm: &[u8]) -> Result<Vec<u8>>

Optimize the given Wasm binary.

Callers must ensure that:

  1. The given Wasm must be the original, uninstrumented Wasm program.

  2. The profile must have been created from an instrumented version of this Wasm program.

Failure to satisfy these requirements may result in a mis-optimized Wasm binary that has divergent behavior from the original Wasm program.

Trait Implementations§

Source§

impl Default for Optimizer

Source§

fn default() -> Self

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

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> 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, 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.