Perf: Replace BTree usage with VecMap
Opened this issue · 0 comments
I spent some time replacing the BTreeMap usage in Clarity with a map implementation using a sorted vec. This could have some memory improvements and I’ve measured some limited runtime improvements while running block replay (5-10% maybe).
There’s probably plenty more gains to be had here: the fallible checked_from_vec
function is faster than the From<Vec>
implementation (which mimics the overwriting inserts behavior of a BTree) and there’s places where the checked_from_vec
could be used instead of from(vec)
. There’s also likely even more opportunity to avoid reallocs by using with_capacity
and reserve
more aggressively (particularly in the merge functions?)
I started a branch with a prototype implementation of the data struct and its integration into Clarity tuples and type maps. There is some test coverage (this is a good candidate for property testing, btw) for the data structure as well:
https://github.com/stacks-network/stacks-core/blob/feat/vecmap/clarity/src/vm/types/vecmap.rs