-
Notifications
You must be signed in to change notification settings - Fork 127
Add benches for the merkle package #794
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
Closed
Closed
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
deb2cf5
root of transactions by stateless merkledb
bianyuanop 0804930
make root generation a function
bianyuanop eb41d9a
preallocate memory for merkle array and consumebytes flag
bianyuanop 77c7952
remove wrong merkleroot docstring
bianyuanop 6dc40e9
add <*.code-workspace> to .gitignore and remove it from git commit
bianyuanop 09b0b6b
move root generation func to merkle package, tx root by items of [txI…
bianyuanop 7586f40
comments about appending outputs to slice of txID
bianyuanop f009424
rebase & blk marshal/unmarshal & merkleroot to ids.ID
bianyuanop 2eae8da
write benches for the merkle package
iFrostizz cd10842
use crypto/rand, fix var name, report allocs
iFrostizz df2344f
put the 10k bench back
iFrostizz df5fec1
Merge branch 'main' into merkle_bench
iFrostizz 8167c70
pass config by parameter
iFrostizz 5800fb5
Revert "rebase & blk marshal/unmarshal & merkleroot to ids.ID"
iFrostizz df97603
resurrect block.go
iFrostizz 2fa9847
Merge branch 'main' into merkle_bench
iFrostizz f604320
apply review changes: call root on view, nits
iFrostizz 0c42f30
Merge branch 'main' into merkle_bench
iFrostizz 86ca814
Merge branch 'main' into merkle_bench
iFrostizz 40774f3
lint
iFrostizz c5565dd
fix lints
iFrostizz b86e5be
Cached state values in the program state (#840)
iFrostizz a781c03
root of transactions by stateless merkledb
iFrostizz 76be5dd
make root generation a function
iFrostizz b87d002
add <*.code-workspace> to .gitignore and remove it from git commit
iFrostizz 987761a
move root generation func to merkle package, tx root by items of [txI…
iFrostizz e42d9f9
Revert "rebase & blk marshal/unmarshal & merkleroot to ids.ID"
iFrostizz 941bd93
sync with main
iFrostizz c8868ca
lint
iFrostizz 87d1213
preallocate memory for merkle array and consumebytes flag
iFrostizz 13e10c3
remove wrong merkleroot docstring
bianyuanop f12ba39
add <*.code-workspace> to .gitignore and remove it from git commit
iFrostizz d046582
move root generation func to merkle package, tx root by items of [txI…
iFrostizz 4b0f9b2
rebase & blk marshal/unmarshal & merkleroot to ids.ID
iFrostizz 46719d3
write benches for the merkle package
iFrostizz 2543ce8
use crypto/rand, fix var name, report allocs
iFrostizz 6451527
put the 10k bench back
iFrostizz a25cae6
pass config by parameter
iFrostizz 5d861d4
Revert "rebase & blk marshal/unmarshal & merkleroot to ids.ID"
iFrostizz 9c1b7cb
apply review changes: call root on view, nits
iFrostizz 45ffd21
lint
iFrostizz e6f44fe
fix lints
iFrostizz 3f3c06b
root of transactions by stateless merkledb
iFrostizz 5dd3d08
make root generation a function
iFrostizz aeedd2f
add <*.code-workspace> to .gitignore and remove it from git commit
iFrostizz ab71cb5
move root generation func to merkle package, tx root by items of [txI…
iFrostizz 9e3491b
Revert "rebase & blk marshal/unmarshal & merkleroot to ids.ID"
iFrostizz 87e75c9
sync with main
iFrostizz b503be3
lint
iFrostizz e294b4d
Merge branch 'merkle_bench' of github.com:iFrostizz/hypersdk into mer…
iFrostizz d46cdbd
sync main
iFrostizz c28ce15
Merge branch 'main' into merkle_bench
iFrostizz 50eac97
remove diff tag
iFrostizz 633a597
Merge remote-tracking branch 'origin/main' into merkle_bench
iFrostizz fe90cfe
Merge branch 'main' into merkle_bench
iFrostizz 4fe496c
Merge branch 'main' into merkle_bench
iFrostizz 22d71c7
don't hash key twice
iFrostizz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package merkle | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ava-labs/avalanchego/database" | ||
"github.com/ava-labs/avalanchego/database/memdb" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/x/merkledb" | ||
) | ||
|
||
// Generate merkle root for a set of items | ||
func GenerateMerkleRoot(ctx context.Context, config merkledb.Config, merkleItems [][]byte, consumeBytes bool) (ids.ID, merkledb.MerkleDB, error) { | ||
batchOps := make([]database.BatchOp, 0, len(merkleItems)) | ||
|
||
for _, item := range merkleItems { | ||
batchOps = append(batchOps, database.BatchOp{ | ||
Key: item, | ||
Value: item, | ||
}) | ||
} | ||
|
||
db, err := merkledb.New(ctx, memdb.New(), config) | ||
if err != nil { | ||
return ids.Empty, nil, err | ||
} | ||
|
||
view, err := db.NewView(ctx, merkledb.ViewChanges{BatchOps: batchOps, ConsumeBytes: consumeBytes}) | ||
if err != nil { | ||
return ids.Empty, nil, err | ||
} | ||
|
||
root, err := view.GetMerkleRoot(ctx) | ||
if err != nil { | ||
return ids.Empty, nil, err | ||
} | ||
|
||
return root, db, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package merkle | ||
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/trace" | ||
"github.com/ava-labs/avalanchego/utils/units" | ||
"github.com/ava-labs/avalanchego/x/merkledb" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
resRoot ids.ID | ||
resDB merkledb.MerkleDB | ||
resErr error | ||
) | ||
|
||
func BenchmarkMerkleTxRoot(b *testing.B) { | ||
for _, size := range []int{10, 100, 1000, 10000} { | ||
ctx := context.TODO() | ||
tracer := trace.Noop | ||
merkleItems := make([][]byte, 0, size) | ||
for i := 0; i < size; i++ { | ||
item := make([]byte, 32) | ||
_, err := rand.Read(item) | ||
require.NoError(b, err) | ||
merkleItems = append(merkleItems, item) | ||
} | ||
|
||
var root ids.ID | ||
var db merkledb.MerkleDB | ||
var err error | ||
|
||
defaultConfig := merkledb.Config{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really want to merge this until this config is largely removed. We need a "single instance" trie that is merkleDB-compatible for #950 |
||
BranchFactor: merkledb.BranchFactor16, | ||
HistoryLength: 100, | ||
IntermediateNodeCacheSize: units.MiB, | ||
ValueNodeCacheSize: units.MiB, | ||
Tracer: tracer, | ||
} | ||
|
||
b.Run(strconv.Itoa(size), func(b *testing.B) { | ||
for n := 0; n < b.N; n++ { | ||
iFrostizz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for i := 0; i < size; i++ { | ||
root, db, err = GenerateMerkleRoot(ctx, defaultConfig, merkleItems, false) | ||
} | ||
} | ||
}) | ||
|
||
// avoid compiler optimizations to cancel out the bench | ||
resRoot = root | ||
resDB = db | ||
resErr = err | ||
} | ||
|
||
b.ReportAllocs() | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.