# no-accumulating-spread

Disallow repeated accumulator spreads within iterations

Spreading an accumulator into its replacement copies every value accumulated so far.
Repeating the replacement in a loop or reduction callback can make total copying grow quadratically.
Instead, you SHOULD use an operation that extends storage without rebuilding the preceding values.

Aliasing can make in-place mutation observably different, so the diagnostic requires a manual rewrite.

- Category: performance
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
function copy(source: int32[]): int32[] {
    let output: int32[] = [];
    for (const value of source) {
        output = [...output, value];
    }

    return output;
}
```

## Accepted

```ds title="main.ds"
function copy(source: int32[]): int32[] {
    let output: int32[] = [];
    for (const value of source) {
        output.push(value);
    }

    return output;
}
```

## Prior art

- [Biome · noAccumulatingSpread](https://github.com/biomejs/biome/search?q=noAccumulatingSpread&type=code)
- [Oxc · no-accumulating-spread](https://github.com/oxc-project/oxc/search?q=no-accumulating-spread&type=code)

[language/linter/src/rules/performance/no_accumulating_spread.rs:7](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/no_accumulating_spread.rs#L7)
