pub struct OptimizationOptions {
    pub reader: ReaderOptions,
    pub writer: WriterOptions,
    pub inlining: InliningOptions,
    pub passopts: PassOptions,
    pub passes: Passes,
    pub features: Features,
    pub converge: bool,
}
Expand description

Optimization options and optimization builder.

This type declares all supported Binaryen options. It can be modified directly or by its builder-pattern methods.

Call OptimizationOptions::run to perform the optimizations.

Fields

reader: ReaderOptions

Options for reading the unoptimized wasm module.

writer: WriterOptions

Options for writing the optimized wasm module.

inlining: InliningOptions

Options related to inlining.

passopts: PassOptions

Options that affect how optimization passes behave.

passes: Passes

The set of optimization passes to apply.

features: Features

The set of wasm-features.

converge: bool

Run passes to convergence, continuing while binary size decreases.

Implementations

Constructors.

Optimize for size.

This corresponds to the -Os argument to wasm-opt, and also the -O argument to wasm-opt.

It applies

Optimize for size, but even more.

It applies

This corresponds to the -Oz argument to wasm-opt.

Do not optimize.

It applies

It adds no default passes.

This corresponds to the -O0 argument to wasm-opt, and also to calling wasm-opt with no -O* optional at all.

Apply basic optimizations.

Useful for fast iteration.

It applies

This corresponds to the -O1 argument to wasm-opt.

Apply most optimizations.

This level of optimization is appropriate for most applications. Higher optimization levels will not necessarily yield better performance, but will take longer to optimize.

It applies

This corresponds to the -O2 argument to wasm-opt.

Apply slower optimizations.

Spends potentially a lot of time on optimizations.

It applies

This corresponds to the -O3 argument to wasm-opt.

Apply the most aggressive optimizations.

Flattens the IR, which can take a lot of time and memory, but may be useful on nested / complex / less-optimized input.

It applies

This corresponds to the -O4 argument to wasm-opt.

Builder methods.

Adds a pass argument to PassOptions::arguments.

Adds a pass to Passes::more_passes.

Execution.

Run the Binaryen wasm optimizer.

This loads a module from a file, runs optimization passes, and writes the module back to a file.

To supply sourcemaps for the input module, and preserve them for the output module, use OptimizationOptions::run_with_sourcemaps.

Errors

Returns error on I/O failure, or if the input fails to parse. If PassOptions::validate is true, it returns an error if the input module fails to validate, or if the optimized module fails to validate.

The Rust API does not support reading a module on stdin, as the CLI does. If infile is empty or “-”, OptimizationError::InvalidStdinPath is returned.

Run the Binaryen wasm optimizer.

This loads a module from a file, runs optimization passes, and writes the module back to a file.

The sourcemap arguments are optional, and only have effect when reading or writing binary wasm files. When using text wat files the respective sourcemap argument is ignored.

Errors

Returns error on I/O failure, or if the input fails to parse. If PassOptions::validate is true, it returns an error if the input module fails to validate, or if the optimized module fails to validate.

The Rust API does not support reading a module on stdin, as the CLI does. If infile is empty or “-”, OptimizationError::InvalidStdinPath is returned.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.