Skip to content

ArrayExtensions.IsSequenceEqual — Use MemoryExtensions.SequenceEqual #142

Description

@leecampbell-codeagent

File: Utilities/ArrayExtensions.cs

The hand-rolled equality loop uses boxed Equals(source[i], other[i]) — that's virtual dispatch and boxing for every element.

// BEFORE
if (!Equals(source[i], other[i])) ...

// AFTER — intrinsic-optimised, SIMD-enabled on .NET 8
return source.AsSpan().SequenceEqual(other.AsSpan());

MemoryExtensions.SequenceEqual is SIMD-vectorised by the JIT on .NET 8 and avoids all boxing. For long[] comparisons across the histogram counts array (which can be ~185KB), this is material.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions