---
title: "slice-preallocation"
description: "Detect slices that can use range-source capacity."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# slice-preallocation

**Default severity:** `note`

Conservatively reports an empty slice followed by exactly one direct append per
iteration of a range with a useful `len`. Preallocating that capacity avoids
repeated growth while preserving zero length.

## Bad

```go
var result []Item
for _, item := range source {
	result = append(result, convert(item))
}
```

## Good

```go
result := make([]Item, 0, len(source))
for _, item := range source {
	result = append(result, convert(item))
}
```

Source: https://strider.gempir.com/analyzers/slice-preallocation/index.mdx
