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) [EN Performance] Reduce memory use and speedup reading single register #2560

Closed

Conversation

fxamacker
Copy link
Member

@fxamacker fxamacker commented Jun 6, 2022

Changes

To reduce memory used when reading single register, make the execution state:

  • use a new type ledger.KeyID to compute ledger.Path.
  • use KeyID which is a simplified ledger.Key with fewer allocs.
  • create ledger.TrieRead and ledger.TrieUpdate without intermediate objects such as ledger.Query and ledger.Update.

With these changes, ledger.Key is only created when updating trie with new payloads.

Updates #1744
Updates #2248
Closes #2559

Benchmark Comparisons

name                     old time/op    new time/op    delta
ExecutionStateRead1-4    7.16µs ± 1%    6.66µs ± 1%   -6.96%  (p=0.000 n=9+10)

name                     old alloc/op   new alloc/op   delta
ExecutionStateRead1-4    1.36kB ± 0%    1.16kB ± 0%  -14.98%  (p=0.000 n=10+8)

name                     old allocs/op  new allocs/op  delta
ExecutionStateRead1-4      15.0 ± 0%      11.0 ± 0%  -26.67%  (p=0.000 n=10+10)

Benchmarks used Go 1.17 on linux_amd64 (Haswell)

ledger.Key requires 4 allocs which can be avoided when reading
registers and generating proofs because we only need register path
and key is an intermediate object created to compute path.

To optimize reading single register, make the execution state:
- use a new type ledger.KeyID to compute ledger.Path.
- use KeyID which is a simplified ledger.Key with less allocs.
- create ledger.TrieRead and ledger.TrieUpdate without intermidate
  objects such as ledger.Query and ledger.Update.

With these changes, ledger.Key is only created when updating trie
with new payloads.

name                     old time/op    new time/op    delta
ExecutionStateRead1-4    7.16µs ± 1%    6.66µs ± 1%   -6.96%  (p=0.000
n=9+10)

name                     old alloc/op   new alloc/op   delta
ExecutionStateRead1-4    1.36kB ± 0%    1.16kB ± 0%  -14.98%  (p=0.000
n=10+8)

name                     old allocs/op  new allocs/op  delta
ExecutionStateRead1-4      15.0 ± 0%      11.0 ± 0%  -26.67%  (p=0.000
n=10+10)
@fxamacker fxamacker added Performance Execution Cadence Execution Team labels Jun 6, 2022
@fxamacker fxamacker self-assigned this Jun 6, 2022
@fxamacker fxamacker changed the title [Execution Node] Reduce memory use and speedup reading single register (WIP) [Execution Node] Reduce memory use and speedup reading single register Jun 10, 2022
@fxamacker fxamacker changed the title (WIP) [Execution Node] Reduce memory use and speedup reading single register (WIP) [EN Performance] Reduce memory use and speedup reading single register Aug 10, 2022
@Kay-Zee
Copy link
Member

Kay-Zee commented Nov 25, 2022

@fxamacker is this blocked by anything?

@fxamacker
Copy link
Member Author

@Kay-Zee This PR was a POC (for discussion). I think it's worthwhile to look into other approaches before proceeding with this PR's approach. I'm closing this PR for now and can open new PR after wrapping up CCF specification and CCF codec.

cc @ramtinms

@fxamacker fxamacker closed this Dec 2, 2022
@fxamacker fxamacker deleted the fxamacker/avoid-ledger-key-allocs-in-ledger-query branch February 2, 2024 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Execution Cadence Execution Team Performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Execution Node] Reduce memory use and speedup reading single register
2 participants