clusterlin: improve TxData::dep_top_idx type (optimization)

The combined size of TxData::dep_top_idx can be 16 KiB with 64
transactions and SetIdx = uint32_t. Use a smaller type where possible to
reduce memory footprint and improve cache locality of m_tx_data.

Also switch from an std::vector to an std::array, reducing allocation
overhead and indirections.
This commit is contained in:
Pieter Wuille 2025-12-21 16:56:14 -05:00
parent 73cbd15d45
commit b75574a653

View File

@ -647,9 +647,13 @@ private:
/** Data type to represent indexing into m_tx_data. */
using TxIdx = DepGraphIndex;
/** Data type to represent indexing into m_set_info. */
using SetIdx = uint32_t;
/** Data type to represent indexing into m_set_info. Use the smallest type possible to improve
* cache locality. */
using SetIdx = std::conditional_t<(SetType::Size() <= 0xff),
uint8_t,
std::conditional_t<(SetType::Size() <= 0xffff),
uint16_t,
uint32_t>>;
/** An invalid SetIdx. */
static constexpr SetIdx INVALID_SET_IDX = SetIdx(-1);
@ -658,7 +662,7 @@ private:
/** The top set for every active child dependency this transaction has, indexed by child
* TxIdx. INVALID_SET_IDX if there is no active dependency with the corresponding child.
*/
std::vector<SetIdx> dep_top_idx;
std::array<SetIdx, SetType::Size()> dep_top_idx;
/** The set of parent transactions of this transaction. Immutable after construction. */
SetType parents;
/** The set of child transactions of this transaction. Immutable after construction. */
@ -977,7 +981,7 @@ public:
tx_data.chunk_idx = num_chunks;
m_set_info[num_chunks++] = SetInfo(depgraph, tx_idx);
// Mark all its dependencies inactive.
tx_data.dep_top_idx.assign(m_tx_data.size(), INVALID_SET_IDX);
tx_data.dep_top_idx.fill(INVALID_SET_IDX);
}
Assume(num_chunks == num_transactions);
// Mark all chunk sets as chunks.