File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,17 @@ use super::ChainstateManager;
2626/// chain, starting from the genesis block (height 0) and continuing
2727/// through to the chain tip.
2828///
29+ /// # Performance Note
30+ /// This iterator traverses blocks sequentially from genesis. Common operations
31+ /// have the following complexity:
32+ /// - `.next()`: O(1) - retrieves next block by height
33+ /// - `.last()`: O(N) - iterates through entire chain
34+ /// - `.nth(n)`: O(N) - skips N blocks
35+ ///
36+ /// For direct access, prefer using [`Chain`] methods:
37+ /// - [`Chain::tip()`] - O(1) access to chain tip (instead of `.last()`)
38+ /// - [`Chain::at_height()`] - O(1) access to specific height (instead of `.nth()`)
39+ ///
2940/// # Lifetime
3041/// The iterator is tied to the lifetime of the [`Chain`] it was created from,
3142/// which in turn is tied to the [`ChainstateManager`]. The iterator becomes
@@ -227,6 +238,11 @@ impl<'a> Chain<'a> {
227238 /// for each block in the chain, starting from the genesis block (height 0) and
228239 /// continuing sequentially to the current tip.
229240 ///
241+ /// # Performance
242+ /// **Warning:** Avoid calling `.last()` on this iterator, as it requires O(N)
243+ /// iteration through all blocks. Use [`chain.tip()`](Chain::tip) instead,
244+ /// which is O(1).
245+ ///
230246 /// # Returns
231247 /// A [`ChainIterator`] that traverses the entire chain.
232248 ///
You can’t perform that action at this time.
0 commit comments