Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3e04c64
fix broken changes from ic-wasm update
kentosugama Apr 11, 2023
919a69e
Merge branch 'master' into wasm-opt
kentosugama Apr 14, 2023
62aa6ca
update ic-wasm dependency
kentosugama Apr 14, 2023
4ad8f13
Expose optimize feature
kentosugama Apr 14, 2023
329e853
add cycles and size optimization defaults as options
kentosugama Apr 14, 2023
41555b6
reword description
kentosugama Apr 17, 2023
20b3436
update expected dynamic libraries
kentosugama Apr 17, 2023
2a9de10
Merge branch 'master' into wasm-opt
kentosugama Apr 18, 2023
75a8895
add tests
kentosugama Apr 18, 2023
0830aab
update changelog
kentosugama Apr 18, 2023
3c4d9a2
fix tests
kentosugama Apr 18, 2023
1f3a749
Update description
kentosugama Apr 18, 2023
8456c73
handle invalid opt level
kentosugama Apr 18, 2023
ed5fb73
error test
kentosugama Apr 18, 2023
7d2c353
Define enums for optimization levels
kentosugama Apr 18, 2023
56579cf
fix error test
kentosugama Apr 18, 2023
b782d96
fix error test
kentosugama Apr 18, 2023
9b58944
fix invalid opt test
kentosugama Apr 19, 2023
dddfc63
remove unnecessary clone
kentosugama Apr 19, 2023
71885b1
Merge branch 'master' into wasm-opt
kentosugama Apr 19, 2023
e4bb808
different back tick notations
kentosugama Apr 19, 2023
99fe887
Merge branch 'master' into wasm-opt
kentosugama Apr 19, 2023
daa8a94
fix documentation
kentosugama Apr 20, 2023
cb3b012
simplify default optimization levels logic
kentosugama Apr 20, 2023
8baab3d
small change to ic-wasm
kentosugama Apr 20, 2023
83d54d7
remove use of serde alias
kentosugama Apr 20, 2023
65fef03
Merge branch 'master' into wasm-opt
kentosugama Apr 21, 2023
5993a8c
Use released ic-wasm
kentosugama Apr 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add cycles and size optimization defaults as options
  • Loading branch information
kentosugama committed Apr 14, 2023
commit 329e85328cefc8df2fb522dec004711f27945e99
2 changes: 1 addition & 1 deletion docs/dfx-json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
},
"optimize": {
"title": "Optimize Canister WASM",
"description": "Whether run `ic-wasm shrink --optimize <level>` after building the Canister. Disabled by default.",
"description": "Whether run `ic-wasm shrink --optimize <level>` after building the Canister. Level can be set to \"cycles\" to optimize for cycle usage, \"size\" to optimize for binary size, or any of \"O4, O3, O2, O1, O0, Oz, Os\". Disabled by default.",
"type": [
"string",
"null"
Expand Down
5 changes: 1 addition & 4 deletions src/dfx/src/lib/builders/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ impl CanisterBuilder for CustomBuilder {
// Custom canister may have WASM gzipped
if is_wasm_format(&wasm)? {
if let Some(level) = optimize {
info!(
self.logger,
"Optimize and shrink WASM module at level {}", level
);
info!(self.logger, "Optimize and shrink WASM module.");
super::optimize_wasm(&wasm, level)?;
} else if shrink {
info!(self.logger, "Shrink WASM module size.");
Expand Down
10 changes: 8 additions & 2 deletions src/dfx/src/lib/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,14 @@ fn optimize_wasm(wasm_path: impl AsRef<Path>, level: &str) -> DfxResult {
let wasm = std::fs::read(wasm_path).context("Could not read the WASM module.")?;
let mut module =
ic_wasm::utils::parse_wasm(&wasm, true).context("Could not parse the WASM module.")?;
ic_wasm::shrink::shrink_with_wasm_opt(&mut module, level)
.context("Could not optimize the WASM module.")?;
match level {
// O3 empirically gives best cycle savings
"cycles" => ic_wasm::shrink::shrink_with_wasm_opt(&mut module, "O3"),
"size" => ic_wasm::shrink::shrink_with_wasm_opt(&mut module, "Oz"),
_ => ic_wasm::shrink::shrink_with_wasm_opt(&mut module, level),
}
.context("Could not optimize the WASM module.")?;

module
.emit_wasm_file(wasm_path)
.with_context(|| format!("Could not write optimized WASM to {:?}.", wasm_path))?;
Expand Down
5 changes: 1 addition & 4 deletions src/dfx/src/lib/builders/motoko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ impl CanisterBuilder for MotokoBuilder {
let optimize = canister_info.get_optimize();
let shrink = canister_info.get_shrink().unwrap_or(true);
if let Some(level) = optimize {
info!(
self.logger,
"Optimize and shrink WASM module at level {}", level
);
info!(self.logger, "Optimize and shrink WASM module.");
super::optimize_wasm(motoko_info.get_output_wasm_path(), level)?;
} else if shrink {
info!(self.logger, "Shrink WASM module size.");
Expand Down
5 changes: 1 addition & 4 deletions src/dfx/src/lib/builders/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ impl CanisterBuilder for RustBuilder {
let optimize = canister_info.get_optimize();
let shrink = canister_info.get_shrink().unwrap_or(true);
if let Some(level) = optimize {
info!(
self.logger,
"Optimize and shrink WASM module at level {}", level
);
info!(self.logger, "Optimize and shrink WASM module.");
super::optimize_wasm(rust_info.get_output_wasm_path(), level)?;
} else if shrink {
info!(self.logger, "Shrink WASM module size.");
Expand Down