Feature Request: Add configuration to ignore small slices (< N elements)
Problem
Prealloc reports all potential preallocations, including small slices (1-3 elements) where:
1.Slice literals are often faster due to zero-value initialization overhead in make() [DELETED: AI bullshit hallucination]
2. Readability tradeoff: []string{"x"} is more idiomatic than make([]string, 1, 2)
3. Minimal performance gain: Growing from 1→2 elements is trivial [for some projects]
Example
components := []string{pageView} // prealloc: Consider preallocating
components = append(components, a.status.View())
Proposed Solution
Add configuration option to ignore small slices:
linters-settings:
prealloc:
min-elements: 5 # Ignore slices < 5 elements
Benefits
- Reduces noise for small, known-size slices
- Focuses prealloc on actual performance wins (large slices, loops)
- Optional feature with no breaking changes
- Aligns with common linter patterns (size thresholds)
This GitHub Issue was created with the partial help of Crush via GLM-4.7 on Z.ai
Feature Request: Add configuration to ignore small slices (< N elements)
Problem
Prealloc reports all potential preallocations, including small slices (1-3 elements) where:
1.
Slice literals are often faster due to zero-value initialization overhead in[DELETED: AI bullshit hallucination]make()2. Readability tradeoff:
[]string{"x"}is more idiomatic thanmake([]string, 1, 2)3. Minimal performance gain: Growing from 1→2 elements is trivial [for some projects]
Example
Proposed Solution
Add configuration option to ignore small slices:
Benefits
This GitHub Issue was created with the partial help of Crush via GLM-4.7 on Z.ai