3 ms·
Why does the object layout matter for this use case? Essentially recording a histogram as described boils down to a single line to record a new observation: thi
by danbruc 12y ago
Why does the object layout matter for this use case? Essentially recording a histogram as described boils down to a single line to record a new observation: this.counts[Math.Floor(offset + scale * Math.Log(value))]++; Maybe using Interlocked to become thread-safe and making the index calculation integers-only if this saves some cycles. Besides getting offset and scale into the same cache line, where does the object layout matter?
- matthewwarren 12y agoThe HdrHistogram class is part of a hierarchy, to make the code more sane, to make implementing specialised versions easier (Short, Long, etc) and to enforce the memory layout: - AbstractHistogramBase [0] - AbstractHistogram [1] - Histogram (or IntHistogram, ShortHistogram) 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/main/java/org/HdrHistogram/AbstractHistogram.java#L32 https://github.com/HdrHistogram/HdrHistogram/blob/master/src... [1] https://github.com/HdrHistogram/HdrHistogram/blob/master/src/main/java/org/HdrHistogram/AbstractHistogram.java#L78 https://github.com/HdrHistogram/HdrHistogram/blob/master/src...