---
title: "OptLevel: type in Emit, TypeShade API reference"
description: "OptLevel, a type in Emit. A named optimization level, spelled like a C compiler's -O flag."
url: https://typeshade.dev/api/optlevel/
language: en
---

# `OptLevel`

Type in Emit

A named optimization level, spelled like a C compiler's -O flag.

`import type { OptLevel } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
type OptLevel = 'O0' | 'O1' | 'O2';
```

## Description

The distinction that matters to a caller is between `'O1'` and `'O2'`, and it concerns whether computed values can change:

- `'O0'`: no pass runs. The module is emitted as authored, which makes it the size baseline to compare the other levels against.
- `'O1'`: only the passes that move or remove values without changing which floating-point operations execute (constant and copy propagation, dead-branch removal, common-subexpression elimination, dead-code elimination). Every value an O1 build computes at runtime is bit-identical to the O0 build’s, on every target.
- `'O2'`: the full pipeline, and the default for every emit function. Adds constant folding on floats, algebraic simplification and loop-invariant code motion. These passes can reorder or replace floating-point operations, so a computed value is not guaranteed to be bit-identical to the O0 build’s.

Choose `'O1'` when a build must be provably value-identical to the unoptimized one, and `'O2'` otherwise. Pass a level to [`emitModuleAt`](https://typeshade.dev/api/emitmoduleat/) to emit WGSL at it, or to [`lowerWgsl`](https://typeshade.dev/api/lowerwgsl/) to get the optimized module without emitting text.

## See also

- [`emitModuleAt`](https://typeshade.dev/api/emitmoduleat/)
- [`lowerWgsl`](https://typeshade.dev/api/lowerwgsl/)

## Source

[`src/core/passes/opt/optimize.ts`, line 324](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/opt/optimize.ts#L324), at commit af54ddad5
