Conversation
| } | ||
| } | ||
| pub fn iter(&self, descending: bool) -> LeafNodeIterator<'_> { | ||
| let mut stack = vec![]; |
There was a problem hiding this comment.
i think it's worth initializing this one with a large enough capacity
There was a problem hiding this comment.
+1 the bump allocator in solana runtime makes dynamic vector resizing deceptively brutal
There was a problem hiding this comment.
I can't see anything in history giving an hint at what vec capacity we want to start with, any hint?
There was a problem hiding this comment.
Vec::with_capacity(self.header().leaf_count as usize);
| leafs: self.slab.iter(is_descending).peekable(), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Think you can do this in a single expression if you import itertools:
self
.slab
.iter(is_descending)
.map(|leaf| (leaf.price(), leaf.quantity()))
.group_by(|(p, q) *p)
.map(|price, group| Level {price, quantity: group.map(|(_, q)| q).sum() })
There was a problem hiding this comment.
The only way i found that would satisfy lifetime requirements is to add an iter function on LevelsIterator, is this how we want it?
pub struct LevelsIterator<'a> {
leafs: LeafNodeIterator<'a>,
}
impl<'a> LevelsIterator<'a> {
fn iter(&'a self) -> Box<dyn Iterator<Item=Level> + 'a> {
Box::new(self.leafs
.map(|leaf| (leaf.price(), leaf.quantity()))
.group_by(|(p, q)| *p)
.into_iter()
.map(|(price, group)| Level {
price: price.get(),
quantity: group.map(|(_, q)| q).sum(),
}))
}
}There was a problem hiding this comment.
I ended up not adding this, i think while more elegant we end up bringing this heap allocation we didn't have before so any program using this will pay. Let me know if you think it is essential
|
AFAICT, these are all non-breaking contract changes and helper utilities. Don't see too much harm in approving |
* fix authority * Fix: fix for authority --------- Co-authored-by: rain <rain@raydium.io>
Work from @tommyip and @codewithgun to use serum-dex from a client
I feel those are things everyone reimplement in their own fork