Files
scriptc/packages/compiler/src/backend/optimization.test.ts
T
Malte Ubl 2372b75ec2 Add an opt-in --optimization=speed posture
Speed is a third native optimization posture next to release (default,
-O2) and dev (-O0). It is optimized exactly like release at the C/LLVM
level and is the switch for optimizations that trade executable size and
build time for run-time speed, so the default release build stays inside
the binary-size budget.

- backend/optimization.ts: the NativeOptimization type, its -O class, and
  cache-key helpers. Release keeps its historical key shapes (absent).
- CLI: build/run/cache warm accept speed; usage text names the trade.
  Bootstrap's routed executable cache mirrors the posture.
- Early executable cache keys and native-feature validation include speed,
  so release, dev, and speed entries never satisfy one another.
- Runtime packs: an optional executable `speed` flavor (-O2, only beside
  release). Speed links it when present and the release objects otherwise;
  library modes link their release flavor. The sanitizer lane follows the
  same flavor key.
- Library profiles accept "speed".
- WASI release-only linker flags apply to speed too.
- bench-runtime: --baseline-optimization/--candidate-optimization and a
  per-contender cold_build_ms.

Release executables are byte-identical to the stack tip for all 14
benchmark workloads (macOS arm64, sha256 of executables built from both
trees).
2026-10-08 15:46:34 -05:00

31 lines
1.3 KiB
TypeScript

import { expect, test } from "vitest";
import {
NATIVE_OPTIMIZATIONS,
isNativeOptimization,
optimizationClass,
optimizationField,
optimizationKeyParts,
} from "./optimization.js";
test("postures parse exactly and speed shares release's optimization class", () => {
expect(NATIVE_OPTIMIZATIONS).toEqual(["release", "dev", "speed"]);
for (const value of NATIVE_OPTIMIZATIONS) expect(isNativeOptimization(value)).toBe(true);
for (const value of ["Release", "fast", "O2", "", undefined, null, 2])
expect(isNativeOptimization(value)).toBe(false);
expect(optimizationClass(undefined)).toBe("release");
expect(optimizationClass("release")).toBe("release");
expect(optimizationClass("speed")).toBe("release");
expect(optimizationClass("dev")).toBe("dev");
});
test("release keeps historical key shapes while dev and speed are keyed apart", () => {
expect(optimizationKeyParts(undefined)).toEqual([]);
expect(optimizationKeyParts("release")).toEqual([]);
expect(optimizationKeyParts("dev")).toEqual(["optimization-dev"]);
expect(optimizationKeyParts("speed")).toEqual(["optimization-speed"]);
expect(optimizationField("release")).toEqual({});
expect(optimizationField(undefined)).toEqual({});
expect(optimizationField("dev")).toEqual({ optimization: "dev" });
expect(optimizationField("speed")).toEqual({ optimization: "speed" });
});