Skip to content

Refactor FastEquals to use SIMD-accelerated SequenceEquals#36

Merged
RevenantX merged 1 commit intoRevenantX:masterfrom
Aman-Anas:patch-1
Mar 8, 2026
Merged

Refactor FastEquals to use SIMD-accelerated SequenceEquals#36
RevenantX merged 1 commit intoRevenantX:masterfrom
Aman-Anas:patch-1

Conversation

@Aman-Anas
Copy link
Contributor

@Aman-Anas Aman-Anas commented Mar 7, 2026

This PR updates the FastEquals method to use the SequenceEquals method for faster comparison. The SequenceEquals method is apparently SIMD-enabled and should have better performance, especially for larger struct objects.

I'm currently trying some benchmarks, will update this PR with results when done.

Here are the benchmark results I got:

| Method        | Mean     | Error     | StdDev    |
|-------------- |---------:|----------:|----------:|
| OldEqualsSame | 3.634 ns | 0.0318 ns | 0.0266 ns |
| OldEqualsDiff | 5.434 ns | 0.0333 ns | 0.0295 ns |
| NewEqualsSame | 1.955 ns | 0.0135 ns | 0.0105 ns |
| NewEqualsDiff | 2.182 ns | 0.0734 ns | 0.1730 ns |

This uses a large struct (12 longs) to measure the difference in perf. It's pretty significant the larger your input data.

Here's the source for the benchmark: Benchmark.txt

I also tested with a very small struct (3 ints) but couldn't really find a measurable difference at that size.

@Aman-Anas
Copy link
Contributor Author

Aman-Anas commented Mar 7, 2026

@RevenantX Do I need to add a #ifdef for platforms that don't support Span? I didn't see any in the SpanWriter class, so maybe it's not needed

@RevenantX
Copy link
Owner

Strange that its faster because when i checked benchmarks SequenceEquals was slower. Maybe depends on structure size or Mono/.Net

@RevenantX RevenantX merged commit 2f74931 into RevenantX:master Mar 8, 2026
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.

2 participants