This change reduces CCoinMap::value_type
from 96 bytes to 80 bytes by more tightly packing it’s data. This allows to cache a lot more transactions in the cache. I’ve achieved this with these changes:
- Refactored
prevector
so it uses a single byte to determine its size when in direct mode - Reduce
CScriptBase
from 28 to 27 indirect bytes - align
CTxOut
to 4 bytes to prevent padding when used as a member inCoin
This tighter packing means more data can be stored in the coinsCache
before it is full and has to be flushed to disk. In my benchmark, -reindex-chainstate
was 6% faster and used 6% less memory. The cache could fit 14% more txo’s before it had to resize.
Some numbers:
runtime h:mm:ss | max RSS kbyte | |
---|---|---|
master -dbcache=5000 | 4:13:59 | 7696728 |
2019-09-more-compact-Coin -dbcache=5000 | 3:57:59 | 7192772 |
change | -6.30% | -6.55% |
The graph shows nicely that the cache is able to be used a lot longer before it is full and flushed to the disk:
I’ve tried this change in combination with #16957 to not cache hash), and then additionally in combination with #16801 :
runtime h:mm:ss | max RSS kbyte | |
---|---|---|
master -dbcache=5000 | 4:13:59 | 7696728 |
2019-09-more-compact-Coin -dbcache=5000 | 3:57:59 | 7192772 |
2019-09-more-compact-Coin & #16957 -dbcache=5500 | 3:51:04 | 6600548 |
2019-09-more-compact-Coin & #16957 & #16801 -dbcache=5500 | 3:38:44 | 6164380 |
With all 3 PR’s applied, reindex was 14% faster and used 20% less memory