Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Zero-allocation Trie/HashDB lookups #3993

Closed
rphmeier opened this issue Dec 29, 2016 · 5 comments
Closed

Zero-allocation Trie/HashDB lookups #3993

rphmeier opened this issue Dec 29, 2016 · 5 comments
Labels
F7-optimisation 💊 An enhancement to provide better overall performance in terms of time-to-completion for a task. M4-core ⛓ Core client code / Rust. P7-nicetohave 🐕 Issue is worth doing eventually.
Milestone

Comments

@rphmeier
Copy link
Contributor

rphmeier commented Dec 29, 2016

Driven by a

fn get_with<F, T>(&self, key: &[u8], f: F) -> Option<T> where F: FnOnce(&[u8]) -> T;
fn get(&self, key: &[u8]) -> Option<Bytes> { self.get_with(key, |b| b.to_vec()) }

or similar alteration to each API (slightly more complex in the presence of trie lookup errors/recorders).
In the state/account modules we can use this to decode values out of the trie immediately without a prior alloc/copy.
In trie lookups we can recursively decode nodes until we find the one with the desired value and then call the provided closure.

@rphmeier rphmeier added F7-optimisation 💊 An enhancement to provide better overall performance in terms of time-to-completion for a task. M4-core ⛓ Core client code / Rust. labels Dec 29, 2016
@rphmeier
Copy link
Contributor Author

While any lookups which go to RocksDB will still end up allocating, anything in the pruning overlay or kvdb working set actually will be fully zero-alloc. A smarter (read: non-cloning) cache in kvdb instead of rocksdb will make this even more effective for ArchiveDB which doesn't keep much around.

@rphmeier
Copy link
Contributor Author

Taken a look into this for now, it seems that it'll be more difficult than anticipated for HashDB for a few reasons:

  • HashDB is typically used as a trait object and generic functions aren't object safe.
  • get_with for HashDB can't be re-entrant because implementations would typically call the closure while holding a read-lock on a cache of some kind which could lead to deadlock.

On the plus side, the TrieDB changes have been pretty simple to make. The rest will come a bit later with a more generic client and separation of JournalDB/HashDB via an associated type.

@5chdn
Copy link
Contributor

5chdn commented May 16, 2017

This optimization labelled issue is inactive since last year.

@paritytech/core-devs Please, confirm within 7 days if this is still relevant. If so, please comment below and add an assignee, or close it otherwise.

@rphmeier
Copy link
Contributor Author

Still relevant, but halfway taken care of.

@5chdn 5chdn added the P7-nicetohave 🐕 Issue is worth doing eventually. label Sep 4, 2017
@5chdn 5chdn added this to the 1.10 & ... milestone Oct 5, 2017
@5chdn 5chdn modified the milestones: 1.10, 1.11 Jan 23, 2018
@5chdn 5chdn modified the milestones: 1.11, 1.12 Mar 1, 2018
@5chdn 5chdn modified the milestones: 1.12, 1.13 Apr 24, 2018
@folsen
Copy link
Contributor

folsen commented May 19, 2018

Closing because it seems of questionable value given @Vurich's closed PR and the difficulty in actually doing this. Would consider reopening if a profiler said this was a big bottleneck.

@folsen folsen closed this as completed May 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
F7-optimisation 💊 An enhancement to provide better overall performance in terms of time-to-completion for a task. M4-core ⛓ Core client code / Rust. P7-nicetohave 🐕 Issue is worth doing eventually.
Projects
None yet
Development

No branches or pull requests

3 participants