forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce CCoinsMap::value_type from 96 to 88 bytes
This PR is similar to bitcoin#17060, but without the incorrect alignment, and with safeguards. CCoinsCacheEntry makes use of Coin's padding to store the flag. Unfortunately great care needs to be taken with this approach that the padding is not accidentally overwritten, e.g. when assigning/moving a coin. This PR solves this issue by chainging CCoinsCacheEntry with getters, and having only a single MutableCoin() method that safely allows to modify the coin member without risking the risk over accidentally overwriting the padding used to store the flags. The original struct layout was like this: 96 CCoinsMap::value_type 36 COutPoint 32 uint256 4 uint32_t 4 >>> PADDING <<< 56 CCoinsCacheEntry 48 Coin 40 CTxOut 8 nValue 32 CScript 4 fCoinBase & nHeight 4 >>> PADDING <<< 1 flags (dirty & fresh) 7 >>> PADDING <<< After that PR the struct layout looks like this: 88 CCoinsMap::value_type 36 COutPoint 32 uint256 4 uint32_t 4 >>> PADDING <<< 48 CCoinsCacheEntry 48 Coin 40 CTxOut 8 nValue 32 CScript 4 fCoinBase & nHeight 4 padding: stores flags (dirty & fresh) That change should translate to ~8% less memory usage of the CCoinsMap.
- Loading branch information
Showing
5 changed files
with
136 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters