Skip to content

Commit

Permalink
Optimize calculation of ledger hashes
Browse files Browse the repository at this point in the history
Problem: when performing transaction application, all merkle ledger
hashes are recomputed for every account update. This is wasteful for a
number of reasons:

  1. Transactions normally contain more than one account update and
     hashes computed by an account update are overwritten by a
     subsequent account update
  2. Ledger's depth is 35, whereas only around 2^18 are actually
     populated. This means that each account update induces a wasteful
     overhead of at least 17 hashes

Solution: defer computation of hashes in mask. When an account is added,
it's stacked in a list `unhashed_accounts` of masks which is processed
at the time of next access to hashes.

This fix improved performance of handling 9-account-update transactions
by ~60% (measured on a laptop).
  • Loading branch information
georgeee committed Nov 30, 2023
1 parent 475f0d5 commit 92a7bee
Showing 1 changed file with 205 additions and 140 deletions.
Loading

0 comments on commit 92a7bee

Please sign in to comment.