Skip to content

Commit

Permalink
Update post-processing with optimizing always
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf committed Feb 28, 2024
1 parent fd97f06 commit bb24ec7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions utils/wasm-builder/src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const OPTIMIZED_EXPORTS: [&str; 7] = [
];

/// Type of the output wasm.
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum OptType {
Meta,
Opt,
Expand Down Expand Up @@ -88,8 +88,6 @@ impl Optimizer {
let mut code = vec![];
module.clone().serialize(&mut code)?;

self.post_check(code.clone(), ty)?;

let exports = if ty == OptType::Opt {
OPTIMIZED_EXPORTS.to_vec()
} else {
Expand Down Expand Up @@ -121,6 +119,8 @@ impl Optimizer {
let mut code = vec![];
module.serialize(&mut code)?;

self.post_check(code.clone(), ty)?;

Ok(code)
}

Expand Down
11 changes: 6 additions & 5 deletions utils/wasm-proc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let original_wasm_path = PathBuf::from(file);
let optimized_wasm_path = original_wasm_path.clone().with_extension("opt.wasm");

// Make pre-handle if input wasm has been built from as-script
let wasm_path = if assembly_script {
// Make sure to run through gear semantic optimizer (preserving only required exports)
let wasm_path = {
let mut optimizer = Optimizer::new(original_wasm_path.clone())?;
optimizer
.insert_start_call_in_export_funcs()
Expand All @@ -232,24 +232,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.expect("Failed to move mutable globals to static");
optimizer.flush_to_file(&optimized_wasm_path);
optimized_wasm_path.clone()
} else {
original_wasm_path.clone()
};

// Make size optimizations
// Make generic size optimizations by wasm-opt
let res = optimize::optimize_wasm(wasm_path, optimized_wasm_path.clone(), "s", true)?;
log::debug!(
"wasm-opt has changed wasm size: {} Kb -> {} Kb",
res.original_size,
res.optimized_size
);

// Insert stack hint for optimized performance on-chain
let mut optimizer = Optimizer::new(optimized_wasm_path.clone())?;
if insert_stack_end {
optimizer.insert_stack_end_export().unwrap_or_else(|err| {
log::debug!("Failed to insert stack end: {}", err);
})
}

// Make sure debug sections are stripped
if strip_custom_sections {
optimizer.strip_custom_sections();
}
Expand Down

0 comments on commit bb24ec7

Please sign in to comment.