paritytech / trie

Base-16 Modified Patricia Merkle Tree (aka Trie)
Apache License 2.0
251 stars 67 forks source link

Return `Arc` instead of `Rc` from the iterators to make them `Send` #185

Closed koute closed 1 year ago

koute commented 1 year ago

This PR replaces the Rc that's returned by the iterators with an Arc.

I need this to make the iterators Send, which I need for further performance improvements in substrate.

cheme commented 1 year ago

Does TrieDBNodeIterator need to be Send (if not, could also make send the other needed iterators as long as they cannot leek rc (the internal triedbnodeiterator))?

koute commented 1 year ago

Does TrieDBNodeIterator need to be Send (if not, could also make send the other needed iterators as long as they cannot leek rc (the internal triedbnodeiterator))?

I just need TrieDBRawIterator to be Send, but since TrieDBNodeIterator is a thin wrapper around it it'll also automatically become Send. There are no other Rcs anywhere left so I think everything now will be Send anyway? actually, sorry, I had a brain fart, indeed TrieDBNodeIterator is not Send since there's a RefCell inside of TrieDB. We could replace the RefCell with a Mutex or something to make it Send (or perhaps do a more thorough refactoring), but for now I'll just leave it as is since that'd complicate things and I don't really need it.

A good old is_sync test maybe?

Good idea. I'll add it.