clusterlin: count chunk deps without loop (optimization)
What changed, and why it matters
This is a small internal code cleanup in Bitcoin Core's transaction clustering/linearization logic. It replaces a loop that counted parent dependencies one-by-one with a faster set-difference count. There is no user-facing change, no network change, and no security-relevant behavior change.
No security action needed. Review as normal code-quality/performance change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In src/cluster_linearize.h, GetLinearization() initializes per-transaction dependency counts and per-chunk dependency counts. The patch replaces an explicit loop over chl_data.parents (looking up each parent’s chunk_rep and incrementing chunk_deps when it differs from the child’s chunk_rep) with a single set-difference expression: (chl_data.parents - chl_chunk_txn).Count(), where chl_chunk_txn is the set of transactions in the child’s own chunk. The result is mathematically identical: it counts parents that are not in the same chunk. This is purely an optimization/refactoring.
Changed components
src/cluster_linearize.hGetLinearization() dependency-counting initializationInspect captured patch +2 / −4
diff --git a/src/cluster_linearize.h b/src/cluster_linearize.h
index 57d6a7a6..882b335f 100644
--- a/src/cluster_linearize.h
+++ b/src/cluster_linearize.h
@@ -1291,10 +1291,8 @@ public:
tx_deps[chl_idx] = chl_data.parents.Count();
auto chl_chunk_rep = chl_data.chunk_rep;
chunk_reps.Set(chl_chunk_rep);
- for (auto par_idx : chl_data.parents) {
- auto par_chunk_rep = m_tx_data[par_idx].chunk_rep;
- chunk_deps[chl_chunk_rep] += (par_chunk_rep != chl_chunk_rep);
- }
+ const auto& chl_chunk_txn = m_tx_data[chl_chunk_rep].chunk_setinfo.transactions;
+ chunk_deps[chl_chunk_rep] += (chl_data.parents - chl_chunk_txn).Count();
}
/** Function to compute the highest element of a chunk, by fallback_order. */
auto max_fallback_fn = [&](TxIdx chunk_rep) noexcept {
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.