EgorBo / SimdJsonSharp

C# bindings for lemire/simdjson (and full C# port)
Apache License 2.0
646 stars 41 forks source link

Avoid some bounds checks #5

Closed tkp1n closed 5 years ago

tkp1n commented 5 years ago

Drops some array bounds checks. Run the following benchmark to compare asm:

Benchmark Source ```csharp [DisassemblyDiagnoser] [ShortRunJob] public class Program { private static ReadOnlySpan Data => new byte[8] { 1,2,3,4,5,6,7,8 }; public IEnumerable Param() { yield return 1; } [Benchmark] [ArgumentsSource(nameof(Param))] public int AccessNoBoundsChekcs(byte c) { return Unsafe.AddByteOffset(ref MemoryMarshal.GetReference(Data), (IntPtr)c); } [Benchmark] [ArgumentsSource(nameof(Param))] public int AccessBoundsChekcs(byte c) { return Data[c]; } static void Main() { BenchmarkRunner.Run(); } } ```
EgorBo commented 5 years ago

@tkp1n thanks! just benchmarked it and I see some improvement. I guess the latest roslyn should handle cases like these now since https://github.com/dotnet/roslyn/pull/24621 is merged.