enum
variant RS-A1007Large size differences between enum variants can adversely impact performance,
as the size of the enumeration is bounded by the largest variant.
Having one very large variant can penalize the memory layout of the enum
.
Consider using Box
for such large variants to store them as pointers on the heap,
or perhaps just holding a reference to them, and not forcing a move of the large
value to inside the enum.
Do note that this lint can't work with values that may change with feature flags and/or at
runtime. Hence, it may lead to possible false negatives or even false positives in cases
where the code path with the enum is rarely hit and the performance hit is too trivial to
consider using a Box
.
enum Item {
Small(usize),
Medium(usize, usize),
Large([usize; 1024]),
}