Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] perf: remove TrieUpdates::removed_nodes #13872

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kien-rise
Copy link
Contributor

@kien-rise kien-rise commented Jan 20, 2025

  • Benchmarks

The basic idea is to combine one HashMap<Nibbles, BranchNodeCompact> and one HashSet<Nibbles> into one HashMap<Nibbles, Option<BranchNodeCompact>> so that the hot operations can be optimized.

Notable changes

pub struct TrieUpdates {
-    pub account_nodes: HashMap<Nibbles, BranchNodeCompact>,
-    pub removed_nodes: HashSet<Nibbles>,
+    pub changed_nodes: HashMap<Nibbles, Option<BranchNodeCompact>>,
     pub storage_tries: B256HashMap<StorageTrieUpdates>,
 }

pub struct StorageTrieUpdates {
     pub is_deleted: bool,
-    pub storage_nodes: HashMap<Nibbles, BranchNodeCompact>,
-    pub removed_nodes: HashSet<Nibbles>,
+    pub changed_nodes: HashMap<Nibbles, Option<BranchNodeCompact>>,
 }

Benchmarks

Total run time for state root calculation (1)

Benchmarks

Summary

  Before After Ratio
ERC20 585111076 510748357 0.8729083724
Raw Transfer 323457659 293110568 0.9061790928
Uniswap 1254878698 1139740260 0.9082473564

(unit: microseconds)

Before

  • erc20-from16-1914-super-low-dependency.zip (30600/150000)
    30,601.00 tps, 1,056,914,565.83 gps, no chain lag, 585111076/609686114 μs
  • raw-transfer-from05-1723-super-low-dependency.zip (54600/280000)
    54,594.73 tps, 1,146,512,812.78 gps, no chain lag, 323457659/332195794 μs
  • uniswap-from14-1848-super-low-dependency.zip (6330/25320)
    6,331.00 tps, 882,451,082.10 gps, no chain lag, 1254878698/1270738569 μs

After

  • erc20-from16-1914-super-low-dependency.zip (30600/150000)
    30,601.00 tps, 1,056,918,521.38 gps, no chain lag, 510748357/534427714 μs
  • raw-transfer-from05-1723-super-low-dependency.zip (54600/280000)
    54,601.00 tps, 1,146,644,512.40 gps, no chain lag, 293110568/302033002 μs
  • uniswap-from14-1848-super-low-dependency.zip (6330/25320)
    6,331.00 tps, 882,444,901.42 gps, no chain lag, 1139740260/1157216500 μs

Others

[183548e8:3c34fef1]
"erc20-from16-1914-super-low-dependency.zip"
{'tps': 33001.0, 'gps': 1139819457.5775578, 'is_chain_lagged': False, 'chain_lag_distance': 0}
{'tps': 33101.0, 'gps': 1143258673.245033, 'is_chain_lagged': False, 'chain_lag_distance': 1}
{'tps': 33301.0, 'gps': 1150171044.6133332, 'is_chain_lagged': False, 'chain_lag_distance': 1}
{'tps': 33701.0, 'gps': 1163995862.5292134, 'is_chain_lagged': True, 'chain_lag_distance': 2}
{'tps': 34501.0, 'gps': 1191624258.379747, 'is_chain_lagged': False, 'chain_lag_distance': 1}
{'tps': 36101.0, 'gps': 1246888006.3610108, 'is_chain_lagged': True, 'chain_lag_distance': 14}

"raw-transfer-from05-1723-super-low-dependency.zip"
{'tps': 58001.0, 'gps': 1218044525.1627908, 'is_chain_lagged': True, 'chain_lag_distance': 2}
{'tps': 58201.0, 'gps': 1222244509.7359223, 'is_chain_lagged': True, 'chain_lag_distance': 3}
{'tps': 58601.0, 'gps': 1230644515.4794521, 'is_chain_lagged': True, 'chain_lag_distance': 6}
{'tps': 59401.0, 'gps': 1247444525.3333333, 'is_chain_lagged': True, 'chain_lag_distance': 7}
{'tps': 61001.0, 'gps': 1281044511.0367346, 'is_chain_lagged': True, 'chain_lag_distance': 13}

"uniswap-from14-1848-super-low-dependency.zip"
{'tps': 6578.742763157895, 'gps': 916967104.8754386, 'is_chain_lagged': False, 'chain_lag_distance': 0}
{'tps': 6616.001543890604, 'gps': 922155973.8782532, 'is_chain_lagged': True, 'chain_lag_distance': 5}
{'tps': 6721.94622451266, 'gps': 936937043.6361192, 'is_chain_lagged': True, 'chain_lag_distance': 23}

@kien-rise kien-rise marked this pull request as draft January 20, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant