Skip to content

Commit 4cfd3df

Browse files
committed
perf(utxo): read record identities directly
Hash-table probes and rehashes only need the txid prefix or txid, but the old accessors decoded output-count metadata on every call. Read those fixed identity bytes from the validated record header instead. A 100,000-record v4 snapshot fixture ran 1.97x to 2.06x faster in forward and reverse 20-run comparisons; Callgrind instruction reads fell 54.3%.
1 parent fffda74 commit 4cfd3df

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

crates/utxo/src/record.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,15 @@ impl UtxoRecord {
367367
}
368368

369369
pub(crate) fn key(&self) -> UtxoKey {
370-
UtxoKey::from_txid(&self.txid())
370+
let mut prefix = [0_u8; 8];
371+
prefix.copy_from_slice(&self.buf.as_bytes()[..8]);
372+
UtxoKey::from_prefix(prefix)
371373
}
372374

373375
pub(crate) fn txid(&self) -> Hash256 {
374-
self.header().txid
376+
let mut txid = [0_u8; TXID_LEN];
377+
txid.copy_from_slice(&self.buf.as_bytes()[..TXID_LEN]);
378+
Hash256::from_le_bytes(&txid)
375379
}
376380

377381
pub(crate) fn is_empty(&self) -> bool {

0 commit comments

Comments
 (0)