Skip to content
C# Micro Optimizations Part 2 – In Arguments
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Exploring C# Micro Optimizations Part 2 – In Arguments

Follow the accompanying blog post here -

Exploring overcoming the mutability issue presented using the ref keyword by using in parameter modifier with readonly structs

When accessing 2 properties in a struct, the performance difference between a ref method and an in method without having a read-only struct, performance is around 10 times slower.

BenchmarkIncrementByRef10000000023.83 ms0.0272 ms0.0241 ms
BenchmarkIncrementByIn100000000238.21 ms0.3108 ms0.2755 ms

When switching the struct to read-only, the performance hit is not evident anymore

BenchmarkIncrementByRef10000000023.93 ms0.1226 ms0.1147 ms
BenchmarkIncrementByIn10000000024.06 ms0.2183 ms0.2042 ms
You can’t perform that action at this time.