mimalloc icon indicating copy to clipboard operation
mimalloc copied to clipboard

Observation: purged and reset statistics types

Open bazineta opened this issue 2 months ago • 0 comments

The answer to this is probably "we know, it's for ABI compatibility", but just in case:

The statistics purged and reset variables are presently mi_stat_count_t, i.e., a 3-tuple of peak, current, and total.

https://github.com/microsoft/mimalloc/blob/09a27098aa6e9286518bd9c74e6ffa7199c3f04e/include/mimalloc-stats.h#L32

However, use of these variables is just as an increasing counter, i.e., their usage actually models a mi_stat_counter_t. They're only ever increased, in these two locations:

https://github.com/microsoft/mimalloc/blob/09a27098aa6e9286518bd9c74e6ffa7199c3f04e/src/os.c#L516 https://github.com/microsoft/mimalloc/blob/09a27098aa6e9286518bd9c74e6ffa7199c3f04e/src/os.c#L548

They're only read here:

https://github.com/microsoft/mimalloc/blob/09a27098aa6e9286518bd9c74e6ffa7199c3f04e/src/stats.c#L333

And that's literally the only use of mi_stat_peak_print(); it's just to extract the peak value from these, the total and current fields are never read, and those fields will always contain the same value. It seems these could be changed to be mi_stat_counter_t.

bazineta avatar Oct 06 '25 20:10 bazineta