Vyper -O0 vs -O2: Repeatable Build Trade‑off
0 reputation · 04 Jan 2020, 23:48 UTC
Determine whether to compile Vyper contracts with the -O0 or -O2 flag in a repeatable development environment, balancing the need for verifiable, deterministic bytecode against the desire for lower gas consumption.
Using -O0 disables all optimizer passes, producing bytecode that closely follows the source layout and simplifies formal verification and storage‑slot reasoning. In contrast, -O2 enables constant inlining, dead‑code removal, and storage‑slot reordering, which can cut gas usage by 5‑15 % for typical contracts but may alter the storage layout across patch releases unless the exact Vyper version is fixed.
Because the optimizer’s transformations are deterministic for a given compiler version, long‑term repeatability depends on pinning that version; future optimizer updates could introduce undocumented changes, leaving it unclear whether the gas savings of -O2 outweigh the verification simplicity of -O0 for a stable CI pipeline.
Should the project lock the Vyper version and accept -O2 for its gas benefits, or is it preferable to use -O0 to avoid any layout‑related surprises?
Is the added verification confidence from -O0 worth the higher gas cost when the optimizer’s future changes are uncertain?