-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Itertools are no longer reexported from util, optimized triedb iter #6322
Conversation
util/src/trie/triedb.rs
Outdated
@@ -293,7 +292,17 @@ impl<'a> TrieDBIterator<'a> { | |||
/// The present key. | |||
fn key(&self) -> Bytes { | |||
// collapse the key_nibbles down to bytes. | |||
self.key_nibbles.iter().step(2).zip(self.key_nibbles.iter().skip(1).step(2)).map(|(h, l)| h * 16 + l).collect() | |||
unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it really require such big block of unsafe
code to be fast?
what about:
let nibbles = self.key_nibbles;
let len = nibbles.len() - 1;
let mut i = 0;
while i < len {
result.push(nibbles[i] * 16 + nibbles[i + 1]);
i += 2;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the checked indexing is too slow? i would guess that using unsafe only for get_unchecked
would be good enough.
LGTM other than @tomusdrw grumble |
util/src/trie/triedb.rs
Outdated
let nibbles = &self.key_nibbles; | ||
let mut i = 0; | ||
let mut result = Bytes::with_capacity(nibbles.len() / 2); | ||
let len = nibbles.len() - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a guarantee that nibbles
is never empty and this can't underflow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, just pushed a fix for that
Triedb benches
old:
new: