perf(node): cache prevout lookups during block apply#3
Conversation
There was a problem hiding this comment.
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.
| 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 | ||
| } |
There was a problem hiding this comment.
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.
No description provided.