Skip to content

perf(node): cache prevout lookups during block apply#3

Open
gg582 wants to merge 1 commit into
mainfrom
perf/block-prevout-cache
Open

perf(node): cache prevout lookups during block apply#3
gg582 wants to merge 1 commit into
mainfrom
perf/block-prevout-cache

Conversation

@gg582

@gg582 gg582 commented May 25, 2026

Copy link
Copy Markdown

No description provided.

@gg582 gg582 requested a review from metaphorics May 25, 2026 14:45

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a BlockPrevoutCache to optimize block application by caching previous output lookups across script verification, maturity checks, and sequence lock validations. Feedback suggests using the entry API for more idiomatic cache lookups and recommends addressing redundant HashMap allocations in BlockLocalUtxoView by sharing the overlay or reusing the view across validation passes.

Comment thread crates/node/src/apply.rs
Comment on lines +617 to +624
fn lookup(&self, set: &UtxoSet, outpoint: bitcoin::OutPoint) -> Option<LiveOutput> {
if let Some(entry) = self.entries.borrow().get(&outpoint) {
return entry.clone();
}
let entry = set.get_entry(&internal_outpoint(&outpoint));
self.entries.borrow_mut().insert(outpoint, entry.clone());
entry
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The lookup method performs a borrow() followed by a borrow_mut() if the entry is missing. While safe in this single-threaded context, it involves redundant internal checks. Using the entry API with borrow_mut() would be more idiomatic, though it would hold the mutable borrow across the set.get_entry call. Given that set.get_entry might involve shard locking, the current approach of dropping the read borrow before the potentially slow lookup is actually a reasonable trade-off to minimize RefCell contention, even if contention is not expected here.

Comment thread crates/node/src/apply.rs
@gg582 gg582 closed this May 25, 2026
@metaphorics metaphorics reopened this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants