# Experiments (/docs/experiments)

marmot changes a default only after a measurement shows that the change is safe and not slower.
The pages in this section record the experiments of each area of the compiler.
Each experiment gives what changed, why, the measurement, the verdict and the next step.
An area can also have research notes, designs and reviews of designs.
A design is a plan. It is not built until its own experiment lands.

## How a change becomes the default [#how-a-change-becomes-the-default]

### Land it behind a switch [#land-it-behind-a-switch]

A change that can alter what a program does, or how fast it runs, lands behind an environment variable.
The switch is off by default, so default output does not change.
An example is `MARMOT_PART_ORDER=1`.

### Pass conformance [#pass-conformance]

`tests/conform` builds and runs each test program with the switch on.
It compares the output, the exit status and the panic message with goldens from the stock Go toolchain.
Changes to code generation also run generated programs and compare their output with gc.

### Compare A against B with perfcmp [#compare-a-against-b-with-perfcmp]

`tests/perfcmp` builds the same programs twice: side A without the switch and side B with it (`-b-env`).
The programs are hello, ten bench programs, sketch and tuios.
perfcmp builds them in dev, -O 2 and -release.
The two sides run in turn, seven runs each, so a change in machine load hits both sides.
perfcmp compares the median wall time, CPU time, peak memory and size.

### Flip only on a clean result [#flip-only-on-a-clean-result]

The default changes only when perfcmp exits 0 in dev, -O 2 and -release.
The commit that flips the default gives the perfcmp numbers.
The old behavior stays available: set the switch to 0, for example `MARMOT_PARKCLEAR=0`.

## The perfcmp verdicts [#the-perfcmp-verdicts]

| Verdict | Exit status | Meaning |
| --- | --- | --- |
| ok | 0 | B is not slower than A by more than 2% and uses at most 3% more memory. |
| WORSE | 1 | B is more than 2% slower in wall or CPU time, or uses more than 3% more memory. |
| INCONCLUSIVE | 4 | The noise of a mode is above 2%, or the load went above half the CPUs. |
| FAILED | 5 | A build or a run failed on one side, or a ratio is not a number. |

The noise line compares each side with itself: its odd runs against its even runs.
A verdict needs noise below 2%, because a 2% change must be visible.

## The goals [#the-goals]

The research notes measure the gaps against marmot's goals, which the notes call SPEC 3c.
For dev builds, the tier0 research note gives these goals against `go build`:

| Measure | Goal |
| --- | --- |
| Run time | at least 1.2x faster |
| Binary size | at most 0.8x |
| Memory | at most 0.7x |
| Build time | at most 0.8x |

## Examples [#examples]

- Line-only source locations passed perfcmp at -O 2 and -release and became the default (commit 08db8598).
- Park clear passed perfcmp in all three modes and became the default (commit 19aaa2c0).
- MIR for tier0 became the default, then a bug showed and the default went back (commits 14d3417b and 77acef69).
  The fix is in, and MIR is opt-in again until its gates pass.

The [Status](/docs/status) page lists the switches that are opt-in now.

## Areas [#areas]

<Cards>
<Card title="Tier0 code generator" href="/docs/experiments/tier0" description="The fast code generator of dev builds and MIR." />

<Card title="Front end and code generator" href="/docs/experiments/frontend" description="Switches in the driver and the code generator." />

<Card title="Backend" href="/docs/experiments/backend" description="LLVM, build time and the release LLVM." />

<Card title="Runtime" href="/docs/experiments/runtime" description="The collector, the scheduler and memory." />

<Card title="Verify" href="/docs/experiments/verify" description="Proofs, budgets and the soundness fuzzer." />

<Card title="Playground and measurement tools" href="/docs/experiments/playground" description="Run in the browser and the benchmark tools." />

<Card title="Modern toolchain features" href="/docs/experiments/toolchain" description="What a modern toolchain has, and where marmot stands." />

<Card title="Self-hosting" href="/docs/experiments/selfhost" description="marmot builds itself: stages, times and sizes." />

<Card title="Go on accelerators" href="/docs/experiments/accelerators" description="Research on deep learning in Go on GPUs and other accelerators." />
</Cards>