This is offered as a “dumb” alternative to @martinus’s very clever #22702, seeking some approach ACK before I spend more time polishing it.
Instead of using a custom allocator, we just take advantage of the statically assertable fact that a node_handle is smaller than the COutpoint key type (or really, key type or value type, but key type happens to be big enough) to build a free list of extracted nodes that we then don’t have to reallocate to reinsert. This would enable us to initialize a cacheMap with any number of nodes we like by inserting with N sequential COutpoints, and then removing them, or by calling reserve (unclear if any functional difference?).
In particular, this does not require mucking with any map internals, it’s just using the external guts in a ‘well defined but weird’ way. Perhaps something like this is less scary @laanwj?
Offered in WIP status for approach ACKs, missing (at least):
- Count total allocation size / count elements in free list
- Deallocate/clear the free list correctly (nodes in free list remain reinsertable after clear)
- make the create_new_cache_coin function have all the emplace-like behaviors we might want
- Any thorough review of correctness5.
- Generically wrapping it for any map where sizeof(K) >= sizeof(node_type).
In contrast to #22702, this approach would likely not save any space in allocations, since it can’t allocate pages at a time.