Context
PR #72 dispatches to SIMD via function pointers whenever simdXxx != nil. There is currently no lower bound on slice length before invoking the SIMD path.
Problem
For small slices, the overhead of a function-pointer call plus SIMD register setup may exceed the cost of the scalar loop. See #72 (review) for more context
Suggested Fix
- Benchmark explicitly with small slice sizes (1, 3, 7, 15 elements) to find the empirical crossover point.
- Add a threshold guard in each dispatch function, e.g.:
const simdMinLen = 32 // tune after benchmarking
if simdAddInplaceFloat32 != nil && len(a) >= simdMinLen {
simdAddInplaceFloat32(a, b)
return
}
// fall through to scalar
The exact value of simdMinLen should be determined per-operation and
per-dtype
Context
PR #72 dispatches to SIMD via function pointers whenever
simdXxx != nil. There is currently no lower bound on slice length before invoking the SIMD path.Problem
For small slices, the overhead of a function-pointer call plus SIMD register setup may exceed the cost of the scalar loop. See #72 (review) for more context
Suggested Fix
The exact value of
simdMinLenshould be determined per-operation andper-dtype