Skip to content

fix: avoid boxing primitive array comparisons - #170

Open
Uddoo wants to merge 3 commits into
HdrHistogram:mainfrom
Uddoo:fix/142-array-sequence-equal
Open

Uddoo wants to merge 3 commits into
HdrHistogram:mainfrom
Uddoo:fix/142-array-sequence-equal

Conversation

@Uddoo

@Uddoo Uddoo commented Oct 19, 2026

Copy link
Copy Markdown

IsSequenceEqual<T> boxes both primitive operands for every array element.
Use span SequenceEqual for primitive arrays, while preserving the existing object.Equals path for custom value/reference types, nullable elements and covariant arrays.
The public generic signature and null-array behaviour stay unchanged.

Closes #142.

Automated validation

  • Release build and full unit suite on .NET 8, 9 and 10: 925 tests per target.
  • dotnet format --verify-no-changes --no-restore passes.
  • dotnet pack --no-build --no-restore --include-symbols succeeds; the package contains all three target assemblies.
  • 26 regression cases cover allocation, lengths/order, mismatches, typed versus object equality, covariance, nulls and floating-point NaN/signed zero.
  • Before the fix, the allocation regression failed with 786,432 allocated bytes; the other 25 cases passed.
  • The final commit received independent testing and code review from a separate AI agent.

Default BenchmarkDotNet 0.15.8 jobs on .NET 8.0.31, Windows 11, Intel i9-13900K:

Benchmark Baseline mean After mean Baseline allocation After allocation
Equal 23,552-element long arrays 101.98 us 3.46 us 1,130,496 B 0 B
Public histogram decoding 28.36 us 27.77 us 189,276 B 189,276 B

The decoding caller compares Type[] and uses the unchanged fallback.
Its timing difference is within the measurements' spread; the post-change distribution was multimodal.
The performance result applies to primitive-array comparison.
The benchmark scaffolding was committed before the implementation change; configuration and results are recorded in plan/benchmarks/.
Performance was measured on .NET 8 only.

AI disclosure

This contribution was produced autonomously by OpenAI Codex under the account owner's authorisation, including code, tests, benchmark execution, commits and PR text.
Independent review and testing were also automated by a separate Codex agent.
No human review or manual verification is claimed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArrayExtensions.IsSequenceEqual — Use MemoryExtensions.SequenceEqual

1 participant