Skip to content

perf(simd): add minimum slice-length threshold before dispatching to SIMD #90

Description

@bennibbelink

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

  1. Benchmark explicitly with small slice sizes (1, 3, 7, 15 elements) to find the empirical crossover point.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions