# large-variant

Disallow variants that disproportionately enlarge an inline union

An unusually large variant determines the storage required by every value of its union type.
Instead, you SHOULD place the large payload behind `Box` when the smaller variants are common enough for the reduced inline size to matter.
Keeping the payload inline can remain faster when the large variant dominates actual use.

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

## Reported

```ds title="main.ds"
struct Packet {
    bytes: [uint8; 256];
}

newtype Message = int32 | Packet;
```

## Accepted

```ds title="main.ds"
import { Box } from "destack:memory";

struct Packet {
    bytes: [uint8; 256];
}

newtype Message = int32 | Box<Packet>;
```

## Prior art

- [Clippy · large_enum_variant](https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant)

[language/linter/src/rules/performance/large_variant.rs:9](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/large_variant.rs#L9)
