base / base/triedb

batch_write into trieDB is much slower than reth's implementation

Open
#179 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
109
Forks
37
PR merge metrics
No merged PRs in 30d

Description

i think the design of the triedb is great. however, when i tried to integrate within reth, it seems that reth's init_genesis (which involves batch write and state root calculation) is much faster than triedb. details are here https://github.com/cliff0412/reth/pull/1/files#diff-e4c46e0b70dd9acdceba2997ebd1749f1666a0f8fa875fd71445a89e6fd4a60fR83

the bench method is described as below
1. generate 100000 random accounts, for each account, generate 5 random storage entries.
2. insert the generated account and storage into reth's plainState database
3. run reth's implementation of `compute_state_root`, which iterates all account and storage and generate state root; persist trieNode into mdbx database.
4. insert account and storage data into this project's `triedb`, and commit, and return the state root.

Both method generate the same state root, so the impl should be correct. however, reth's implementation only takes 73us, while `triedb` takes 2.5s. the most time consuming part is performing `commit`.

do i use this crate wrongly or indeed is very slow?

to run
```
cargo bench -p reth-db-common --bench state_root_comparison
```

Image

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running `cargo bench -p reth-db-common --bench state_root_comparison` and review the linked reth comparison and benchmark steps. Focus on the `commit` portion, then determine whether the large timing difference comes from incorrect crate usage or triedb's implementation. Done means providing benchmark evidence and a clear resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.