Know thy .NET object memory layout
mattwarren.org
mattwarren.org
If order is otherwise unimportant to you (coding standard demanding alphabetic order, offsets that must match a layout provided by someone else, etc), you could do it yourself when creating your class/struct.
If you really need a specific memory layout, you need to use a trick like the one in the article, or resort to LayoutKind Sequential[0].
This is part of the answer. Despite an attempt to align a struct to leverage the cache, it was getting rearranged.
Of course, there is also less inlining and the schedule behind the async command really doesn't like it when you get more active pseudo-threads than cores.
In the end, the data flow TPL was the only implementation that was roughly in the same ball park.
BTW have you looked at Distuptor.NET[0], the .NET port of Disruptor? It's a high-speed ring buffer written in .NET, that might contain some tricks to get your perf closer to the Go version.
So the 2 things are a trade-off.
AbstractHistogram contains all the "Hot" fields, i.e. the ones that you want to get into memory at the same time, with the least possible work. These fields are used repeatedly when storing values, which is the "Hot Path" for HdrHistogram.
AbstractHistogramBase contains a lot of fields that are only used when you are iterating or displaying results, so the idea is that they are kept out of the way when recording values.
[0] https://github.com/HdrHistogram/HdrHistogram/blob/master/src...
[1] https://github.com/HdrHistogram/HdrHistogram/blob/master/src...