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
simplify default optimization levels logic
  • Loading branch information
kentosugama committed Apr 20, 2023
commit cb3b01281b12ada2cef1903d6637bbcc6d8f13e5
40 changes: 11 additions & 29 deletions docs/dfx-json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
},
"optimize": {
"title": "Optimize Canister WASM",
"description": "Invoke wasm level optimizations after building the Canister. Optimization 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.",
"description": "Invoke wasm level optimizations after building the canister. Optimization 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.",
"default": null,
"anyOf": [
{
Expand Down Expand Up @@ -872,34 +872,16 @@
},
"WasmOptLevel": {
"title": "Wasm Optimization Levels",
"description": "Wasm optimization levels that are passed to `wasm-opt`. \"cycles\" defaults to O3, \"size\" defaults to Oz. O4 through O0 focus on performance (with O0 being no optimizations), and Oz and Os focus on reducing binary size, where Oz is more aggressive than Os.",
"oneOf": [
{
"type": "string",
"enum": [
"O4",
"O3",
"O2",
"O1",
"O0",
"Oz",
"Os"
]
},
{
"description": "Defaults to O3",
"type": "string",
"enum": [
"cycles"
]
},
{
"description": "Defaults to Oz",
"type": "string",
"enum": [
"size"
]
}
"description": "Wasm optimization levels that are passed to `wasm-opt`. \"cycles\" defaults to O3, \"size\" defaults to Oz. O4 through O0 focus on performance (with O0 performing no optimizations), and Oz and Os focus on reducing binary size, where Oz is more aggressive than Os. O3 and Oz empirically give best cycle savings and code size savings respectively.",
"type": "string",
"enum": [
"O4",
"O3",
"O2",
"O1",
"O0",
"Oz",
"Os"
]
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/dfx-core/src/config/model/dfinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,18 @@ pub struct ConfigCanistersCanisterRemote {

/// # Wasm Optimization Levels
/// Wasm optimization levels that are passed to `wasm-opt`. "cycles" defaults to O3, "size" defaults to Oz.
/// O4 through O0 focus on performance (with O0 being no optimizations), and Oz and Os focus on reducing binary size, where Oz is more aggressive than Os.
/// O4 through O0 focus on performance (with O0 performing no optimizations), and Oz and Os focus on reducing binary size, where Oz is more aggressive than Os.
/// O3 and Oz empirically give best cycle savings and code size savings respectively.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub enum WasmOptLevel {
/// Defaults to O3
#[serde(rename = "cycles")]
Cycles,
/// Defaults to Oz
#[serde(rename = "size")]
Size,
// Specific performance levels
O4,
#[serde(alias = "cycles")]
O3,
O2,
O1,
O0,
// Specific size levels

#[serde(alias = "size")]
Oz,
Os,
}
Expand Down Expand Up @@ -224,7 +220,8 @@ pub struct ConfigCanistersCanister {
pub shrink: Option<bool>,

/// # Optimize Canister WASM
/// Invoke wasm level optimizations after building the Canister. Optimization 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.
/// Invoke wasm level optimizations after building the canister. Optimization 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.
#[serde(default)]
pub optimize: Option<WasmOptLevel>,

Expand Down
5 changes: 4 additions & 1 deletion src/dfx/src/lib/builders/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ 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.");
info!(
self.logger,
"Optimize and shrink WASM module at level {}", level
);
super::optimize_wasm(&wasm, level)?;
} else if shrink {
info!(self.logger, "Shrink WASM module size.");
Expand Down
9 changes: 2 additions & 7 deletions src/dfx/src/lib/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,8 @@ fn optimize_wasm(wasm_path: impl AsRef<Path>, level: &WasmOptLevel) -> 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.")?;
match level {
// O3 and Oz empirically give best cycle savings and code size savings respectively
WasmOptLevel::Cycles => ic_wasm::shrink::shrink_with_wasm_opt(&mut module, "O3"),
WasmOptLevel::Size => ic_wasm::shrink::shrink_with_wasm_opt(&mut module, "Oz"),
_ => ic_wasm::shrink::shrink_with_wasm_opt(&mut module, &level.to_string()),
}
.context("Could not optimize the WASM module.")?;
ic_wasm::shrink::shrink_with_wasm_opt(&mut module, &level.to_string())
.context("Could not optimize the WASM module.")?;

module
.emit_wasm_file(wasm_path)
Expand Down
5 changes: 4 additions & 1 deletion src/dfx/src/lib/builders/motoko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ 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.");
info!(
self.logger,
"Optimize and shrink WASM module at level {}", level
);
super::optimize_wasm(motoko_info.get_output_wasm_path(), level)?;
} else if shrink {
info!(self.logger, "Shrink WASM module size.");
Expand Down
5 changes: 4 additions & 1 deletion src/dfx/src/lib/builders/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ 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.");
info!(
self.logger,
"Optimize and shrink WASM module at level {}", level
);
super::optimize_wasm(rust_info.get_output_wasm_path(), level)?;
} else if shrink {
info!(self.logger, "Shrink WASM module size.");
Expand Down