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

Optimize MTrie Checkpoint (regCount & regSize): -9GB alloc/op, -110 milllion allocs/op, -4GB file size #2126

Merged
merged 21 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3ed616c
Add MTrie.regCount and MTrie.regSize to reduce mem
fxamacker Mar 9, 2022
e555900
Merge branch 'master' into fxamacker/move-regcount-regsize-to-trie
fxamacker Mar 9, 2022
697f366
Avoid heap allocs for goroutine in update()
fxamacker Mar 10, 2022
51bd891
Check for nil payload in Payload funcs
fxamacker Mar 10, 2022
a4d12a5
Avoid deep copy of compactLeaf payload in update
fxamacker Mar 15, 2022
9ec0a52
Use empty payload value to test unallocated reg
fxamacker Mar 16, 2022
09a0620
Move updateResult type outside of update()
fxamacker Mar 16, 2022
ae98303
Merge branch 'master' into fxamacker/move-regcount-regsize-to-trie
fxamacker Mar 16, 2022
ced2c8f
Encode length of encoded payload value in 4 bytes
fxamacker Mar 18, 2022
029ad04
Bump checkpoint file format to v5
fxamacker Mar 22, 2022
532fb46
Support V4 and V5 in checkpoint extraction cmd
fxamacker Mar 22, 2022
051ba8e
Add comments about WaitGroup vs channel in update
fxamacker Mar 22, 2022
953571a
Fix typo in a comment
fxamacker Mar 22, 2022
d9573d0
Add test for trie update with mixed prune flag
fxamacker Mar 22, 2022
38a12bc
Remove some blank lines after comments
fxamacker Mar 22, 2022
4bcc1c8
Extract some logic from trie update to new funcs
fxamacker Mar 22, 2022
cbb8805
Fix comment for TestTrieAllocatedRegCountRegSizeWithMixedPruneFlag
fxamacker Mar 23, 2022
67368d2
Add "compute" prefix to two function names
fxamacker Mar 23, 2022
7e2a913
Merge branch 'master' into fxamacker/move-regcount-regsize-to-trie
fxamacker Mar 23, 2022
c90c1db
Merge pull request #2174 from onflow/fxamacker/bump-checkpoint-version
fxamacker Mar 23, 2022
f8dfffd
Merge pull request #2165 from onflow/fxamacker/optimize-encoded-paylo…
fxamacker Mar 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package extract

import (
"encoding/binary"
"encoding/hex"
"fmt"
"os"
Expand All @@ -11,6 +12,7 @@ import (

"github.com/onflow/flow-go/cmd/util/cmd/common"
"github.com/onflow/flow-go/ledger/common/hash"
"github.com/onflow/flow-go/ledger/complete/wal"
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/metrics"
Expand Down Expand Up @@ -117,13 +119,43 @@ func run(*cobra.Command, []string) {
if err != nil {
log.Fatal().Err(err).Msg("invalid root checkpoint")
}
const crcLength = 4
_, err = f.Seek(-(hash.HashLen + crcLength), 2 /* relative from end */)
if err != nil {
log.Fatal().Err(err).Msg("invalid root checkpoint")

const (
encMagicSize = 2
encVersionSize = 2
crcLength = 4
encNodeCountSize = 8
encTrieCountSize = 2
headerSize = encMagicSize + encVersionSize
)

// read checkpoint version
header := make([]byte, headerSize)
n, err := f.Read(header)
if err != nil || n != headerSize {
log.Fatal().Err(err).Msg("failed to read version from root checkpoint")
}

magic := binary.BigEndian.Uint16(header)
version := binary.BigEndian.Uint16(header[encMagicSize:])

if magic != wal.MagicBytes {
log.Fatal().Err(err).Msg("invalid magic bytes in root checkpoint")
}

if version <= 3 {
_, err = f.Seek(-(hash.HashLen + crcLength), 2 /* relative from end */)
if err != nil {
log.Fatal().Err(err).Msg("invalid root checkpoint")
}
} else {
_, err = f.Seek(-(hash.HashLen + encNodeCountSize + encTrieCountSize + crcLength), 2 /* relative from end */)
if err != nil {
log.Fatal().Err(err).Msg("invalid root checkpoint")
}
}

n, err := f.Read(stateCommitment[:])
n, err = f.Read(stateCommitment[:])
if err != nil || n != hash.HashLen {
log.Fatal().Err(err).Msg("failed to read state commitment from root checkpoint")
}
Expand Down
Loading