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
impl Optimizer
Sourcepub fn min_total_calls(&mut self, min: u64) -> &mut Self
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.
Sourcepub fn min_ratio(&mut self, min: f64) -> Result<&mut Self>
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.
Sourcepub fn max_inline_depth(&mut self, max: usize) -> &mut Self
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.
Sourcepub fn emit_feedback_counters(&mut self, emit: bool) -> &mut Self
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:
-
A counter for how many times we guessed correctly.
-
A counter for how many times we guessed incorrectly.
You can extract this data using the
FeedbackCounters type.
This option is false by default.
Sourcepub fn fuel(&mut self, fuel: Option<u32>) -> &mut Self
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.
Sourcepub fn optimize(&self, profile: &Profile, wasm: &[u8]) -> Result<Vec<u8>>
pub fn optimize(&self, profile: &Profile, wasm: &[u8]) -> Result<Vec<u8>>
Optimize the given Wasm binary.
Callers must ensure that:
-
The given Wasm must be the original, uninstrumented Wasm program.
-
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.