Skip to content

Release Build

By default, zolo build compiles in debug mode: the build is fast, but the binary is not optimised — suitable during development. For distribution, add --release: Cranelift applies its optimisations and the resulting executable is noticeably faster on loops and computation-heavy code.

The example below measures the time for a loop of one million iterations, making the performance difference observable:

Compare zolo build (debug) with zolo build --release: the elapsed value should be lower in the optimised build.

04-release.zolo
// Feature: optimized native build — `zolo build --release`
// Syntax: `zolo build file.zolo --release`
// When to use: ship a fast binary. `--release` enables Cranelift
//   optimizations; the default (debug) build favors compile speed.

// Run:
//   zolo build 30-compilation/04-release.zolo            # debug (fast to build)
//   zolo build 30-compilation/04-release.zolo --release  # optimized
//
// `--release` combines with any `--emit` (e.g. `--emit zex --release`)
// and with `--standalone` / `--windowed`.

use std::os

// A loop heavy enough that the optimizer matters.
let start = os.clock()
var acc = 0
for i in 0..1_000_000 {
  acc += i % 7
}
print("acc =", acc)
print("elapsed =", os.clock() - start)

// expected: acc =	2999997  (timing varies; --release is noticeably faster)

Requires the Zolo CLI/host — open in the playground or run locally.

--release combines with any --emit — for example, zolo build --emit obj --release writes an optimised object file. It also works with --standalone and --windowed (distribution, covered in chapter 31).

enespt-br