Skip to content

Commit 41d4e54

Browse files
authored
docs: improve optimizer_runs documentation to be more accurate (#8875)
improve optimizer_runs documentation
1 parent 81349ed commit 41d4e54

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

crates/cli/src/opts/build/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ pub struct CompilerArgs {
3030
#[serde(skip)]
3131
pub optimize: bool,
3232

33-
/// The number of optimizer runs.
33+
/// The number of runs specifies roughly how often each opcode of the deployed code will be
34+
/// executed across the life-time of the contract. This means it is a trade-off parameter
35+
/// between code size (deploy cost) and code execution cost (cost after deployment).
36+
/// An `optimizer_runs` parameter of `1` will produce short but expensive code. In contrast, a
37+
/// larger `optimizer_runs` parameter will produce longer but more gas efficient code.
3438
#[arg(long, value_name = "RUNS")]
3539
#[serde(skip_serializing_if = "Option::is_none")]
3640
pub optimizer_runs: Option<usize>,

crates/config/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,16 @@ pub struct Config {
212212
pub offline: bool,
213213
/// Whether to activate optimizer
214214
pub optimizer: bool,
215-
/// Sets the optimizer runs
215+
/// The number of runs specifies roughly how often each opcode of the deployed code will be
216+
/// executed across the life-time of the contract. This means it is a trade-off parameter
217+
/// between code size (deploy cost) and code execution cost (cost after deployment).
218+
/// An `optimizer_runs` parameter of `1` will produce short but expensive code. In contrast, a
219+
/// larger `optimizer_runs` parameter will produce longer but more gas efficient code. The
220+
/// maximum value of the parameter is `2**32-1`.
221+
///
222+
/// A common misconception is that this parameter specifies the number of iterations of the
223+
/// optimizer. This is not true: The optimizer will always run as many times as it can
224+
/// still improve the code.
216225
pub optimizer_runs: usize,
217226
/// Switch optimizer components on or off in detail.
218227
/// The "enabled" switch above provides two defaults which can be

0 commit comments

Comments
 (0)