> ## Documentation Index
> Fetch the complete documentation index at: https://codspeed.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Allocation Exclusion

> Exclude memory-allocation time from CPU simulation results to remove allocator variance.

Allocators are a common source of benchmark variance. Their cost depends on the
operating system, the allocator implementation, and its version. If you are
optimizing your own code and the allocator itself is not what you are measuring,
that cost is noise in your measurements.

## How it works

CodSpeed tags every flamegraph frame that belongs to an allocator, covering the
standard allocation functions, common allocators such as `jemalloc` and
language-runtime allocators. With allocation exclusion enabled, CodSpeed sums
the time spent in those frames, including everything they call, and subtracts it
from the reported benchmark value.

The flamegraph still shows the allocator frames, marked with an `Allocator` tag
in the tooltip. Only the reported benchmark value changes.

## When to use it

* Exclude allocations when allocator noise dominates a micro-benchmark and you
  are optimizing your own code.
* Keep allocations included when the allocator itself is what you are measuring
  or optimizing.

Allocation exclusion complements the allocator-variance strategies in
[Reducing allocator variance](/docs/instruments/cpu/reducing-variance#reducing-allocator-variance).
Tuning or swapping the allocator reduces variance, while exclusion leaves the
allocator cost out of the reported value entirely.

## Enable it

Pass the flag to the CodSpeed CLI:

```sh theme={null}
codspeed run --exclude-allocations -- <your bench command>
```

In GitHub Actions, set the environment variable on the CodSpeed action. There is
no dedicated action input, so enable it through the environment:

```yaml .github/workflows/codspeed.yml highlight={16} theme={null}
name: CodSpeed Benchmarks

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  benchmarks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: CodSpeedHQ/action@v4
        env:
          CODSPEED_EXCLUDE_ALLOCATIONS: "true"
        with:
          mode: simulation
          run: <your bench command>
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Reducing Variance" href="/docs/instruments/cpu/reducing-variance" icon="chart-line">
    Techniques to make your benchmarks more stable across runs.
  </Card>

  <Card title="Unexpected Regressions" href="/docs/instruments/cpu/regression-causes" icon="triangle-exclamation">
    Understand why benchmarks can regress without code changes.
  </Card>
</CardGroup>
