mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
mapNextTx: use pointer as key, simplify value
Saves about 10% of application memory usage once the mempool warms up. Since the mempool is DynamicUsage-regulated, this will translate to a larger mempool in the same amount of space. Map value type: eliminate the vin index; no users of the map need to know which input of the transaction is spending the prevout. Map key type: replace the COutPoint with a pointer to a COutPoint. A COutPoint is 36 bytes, but each COutPoint is accessible from the same map entry's value. A trivial DereferencingComparator functor allows indirect map keys, but the resulting syntax is misleading: `map.find(&outpoint)`. Implement an indirectmap that acts as a wrapper to a map that uses a DereferencingComparator, supporting a syntax that accurately reflect the container's semantics: inserts and iterators use pointers since they store pointers and need them to remain constant and dereferenceable, but lookup functions take const references.
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#ifndef BITCOIN_MEMUSAGE_H
|
||||
#define BITCOIN_MEMUSAGE_H
|
||||
|
||||
#include "indirectmap.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <map>
|
||||
@@ -106,6 +108,20 @@ static inline size_t IncrementalDynamicUsage(const std::map<X, Y, Z>& m)
|
||||
return MallocUsage(sizeof(stl_tree_node<std::pair<const X, Y> >));
|
||||
}
|
||||
|
||||
// indirectmap has underlying map with pointer as key
|
||||
|
||||
template<typename X, typename Y>
|
||||
static inline size_t DynamicUsage(const indirectmap<X, Y>& m)
|
||||
{
|
||||
return MallocUsage(sizeof(stl_tree_node<std::pair<const X*, Y> >)) * m.size();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
static inline size_t IncrementalDynamicUsage(const indirectmap<X, Y>& m)
|
||||
{
|
||||
return MallocUsage(sizeof(stl_tree_node<std::pair<const X*, Y> >));
|
||||
}
|
||||
|
||||
// Boost data structures
|
||||
|
||||
template<typename X>
|
||||
|
||||
Reference in New Issue
Block a user