clusterlin: improve TxData::dep_top_idx type (optimization)
What changed, and why it matters
This is a straightforward memory-use and performance optimization inside Bitcoin Core's transaction clustering code. It changes an internal index type to the smallest unsigned integer that fits the data, and switches a dynamically-sized vector to a fixed-size array. There is no security-relevant change here—no bug fix, no input validation change, no cryptographic change, and no behavior change visible outside the module.
No security action needed. Treat as a normal performance refactor during routine review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In src/cluster_linearize.h, the patch makes SetIdx a type alias to uint8_t, uint16_t, or uint32_t depending on SetType::Size() at compile time, and replaces std::vector
Changed components
src/cluster_linearize.hTxData::dep_top_idxSetIdx type aliasInspect captured patch +9 / −5
diff --git a/src/cluster_linearize.h b/src/cluster_linearize.h
index 50606942..2b935da6 100644
--- a/src/cluster_linearize.h
+++ b/src/cluster_linearize.h
@@ -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.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.