-
Notifications
You must be signed in to change notification settings - Fork 674
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
MerkleDB Reduce buffer creation/memcopy on path construction #2124
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
435d1cc
Update trie_test.go
dboehm-avalabs 56b0773
Update trie_test.go
dboehm-avalabs 9a76c04
delete unused functions
dboehm-avalabs d01a389
Update path_test.go
dboehm-avalabs 5bbd9b3
Update path.go
dboehm-avalabs cab3636
Merge branch 'dev' into optimizations
dboehm-avalabs 21f585f
Merge branch 'dev' into optimizations
dboehm-avalabs 1dc166c
Merge branch 'dev' into optimizations
dboehm-avalabs 712f68f
Merge branch 'dev' into optimizations
dboehm-avalabs f98fd72
remove prefix check allocation
dboehm-avalabs a4043fd
Merge branch 'dev' into optimizations
1b63507
add test
5097a10
Merge branch 'optimizations' of github.com:ava-labs/avalanchego into …
e0c89ee
Update path.go
dboehm-avalabs 755bb89
Update path.go
dboehm-avalabs 39f6813
Merge branch 'dev' into optimizations
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 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
This file contains 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 |
---|---|---|
|
@@ -275,70 +275,76 @@ func Test_Path_Append(t *testing.T) { | |
} | ||
} | ||
|
||
func Test_Path_Extend(t *testing.T) { | ||
func Test_Path_AppendExtend(t *testing.T) { | ||
require := require.New(t) | ||
|
||
path2 := NewPath([]byte{0b1000_0000}, BranchFactor2).Take(1) | ||
p := NewPath([]byte{0b01010101}, BranchFactor2) | ||
extendedP := path2.Extend(p) | ||
require.Equal([]byte{0b10101010, 0b1000_0000}, extendedP.Bytes()) | ||
extendedP := path2.AppendExtend(0, p) | ||
require.Equal([]byte{0b10010101, 0b01000_000}, extendedP.Bytes()) | ||
require.Equal(byte(1), extendedP.Token(0)) | ||
require.Equal(byte(0), extendedP.Token(1)) | ||
require.Equal(byte(1), extendedP.Token(2)) | ||
require.Equal(byte(0), extendedP.Token(3)) | ||
require.Equal(byte(1), extendedP.Token(4)) | ||
require.Equal(byte(0), extendedP.Token(5)) | ||
require.Equal(byte(1), extendedP.Token(6)) | ||
require.Equal(byte(0), extendedP.Token(7)) | ||
require.Equal(byte(1), extendedP.Token(8)) | ||
|
||
p = NewPath([]byte{0b01010101, 0b1000_0000}, BranchFactor2).Take(9) | ||
extendedP = path2.Extend(p) | ||
require.Equal([]byte{0b10101010, 0b1100_0000}, extendedP.Bytes()) | ||
require.Equal(byte(0), extendedP.Token(2)) | ||
require.Equal(byte(1), extendedP.Token(3)) | ||
require.Equal(byte(0), extendedP.Token(4)) | ||
require.Equal(byte(1), extendedP.Token(5)) | ||
require.Equal(byte(0), extendedP.Token(6)) | ||
require.Equal(byte(1), extendedP.Token(7)) | ||
require.Equal(byte(0), extendedP.Token(8)) | ||
require.Equal(byte(1), extendedP.Token(9)) | ||
|
||
p = NewPath([]byte{0b0101_0101, 0b1000_0000}, BranchFactor2).Take(9) | ||
extendedP = path2.AppendExtend(0, p) | ||
require.Equal([]byte{0b1001_0101, 0b0110_0000}, extendedP.Bytes()) | ||
require.Equal(byte(1), extendedP.Token(0)) | ||
require.Equal(byte(0), extendedP.Token(1)) | ||
require.Equal(byte(1), extendedP.Token(2)) | ||
require.Equal(byte(0), extendedP.Token(3)) | ||
require.Equal(byte(1), extendedP.Token(4)) | ||
require.Equal(byte(0), extendedP.Token(5)) | ||
require.Equal(byte(1), extendedP.Token(6)) | ||
require.Equal(byte(0), extendedP.Token(7)) | ||
require.Equal(byte(1), extendedP.Token(8)) | ||
require.Equal(byte(0), extendedP.Token(2)) | ||
require.Equal(byte(1), extendedP.Token(3)) | ||
require.Equal(byte(0), extendedP.Token(4)) | ||
require.Equal(byte(1), extendedP.Token(5)) | ||
require.Equal(byte(0), extendedP.Token(6)) | ||
require.Equal(byte(1), extendedP.Token(7)) | ||
require.Equal(byte(0), extendedP.Token(8)) | ||
require.Equal(byte(1), extendedP.Token(9)) | ||
require.Equal(byte(1), extendedP.Token(10)) | ||
|
||
path4 := NewPath([]byte{0b0100_0000}, BranchFactor4).Take(1) | ||
p = NewPath([]byte{0b0101_0101}, BranchFactor4) | ||
extendedP = path4.Extend(p) | ||
require.Equal([]byte{0b0101_0101, 0b0100_0000}, extendedP.Bytes()) | ||
extendedP = path4.AppendExtend(0, p) | ||
require.Equal([]byte{0b0100_0101, 0b0101_0000}, extendedP.Bytes()) | ||
require.Equal(byte(1), extendedP.Token(0)) | ||
require.Equal(byte(1), extendedP.Token(1)) | ||
require.Equal(byte(0), extendedP.Token(1)) | ||
require.Equal(byte(1), extendedP.Token(2)) | ||
require.Equal(byte(1), extendedP.Token(3)) | ||
require.Equal(byte(1), extendedP.Token(4)) | ||
require.Equal(byte(1), extendedP.Token(5)) | ||
|
||
path16 := NewPath([]byte{0b0001_0000}, BranchFactor16).Take(1) | ||
p = NewPath([]byte{0b0001_0001}, BranchFactor16) | ||
extendedP = path16.Extend(p) | ||
require.Equal([]byte{0b0001_0001, 0b0001_0000}, extendedP.Bytes()) | ||
extendedP = path16.AppendExtend(0, p) | ||
require.Equal([]byte{0b0001_0000, 0b0001_0001}, extendedP.Bytes()) | ||
require.Equal(byte(1), extendedP.Token(0)) | ||
require.Equal(byte(1), extendedP.Token(1)) | ||
require.Equal(byte(0), extendedP.Token(1)) | ||
require.Equal(byte(1), extendedP.Token(2)) | ||
require.Equal(byte(1), extendedP.Token(3)) | ||
|
||
p = NewPath([]byte{0b0001_0001, 0b0001_0001}, BranchFactor16) | ||
extendedP = path16.Extend(p) | ||
require.Equal([]byte{0b0001_0001, 0b0001_0001, 0b0001_0000}, extendedP.Bytes()) | ||
extendedP = path16.AppendExtend(0, p) | ||
require.Equal([]byte{0b0001_0000, 0b0001_0001, 0b0001_0001}, extendedP.Bytes()) | ||
require.Equal(byte(1), extendedP.Token(0)) | ||
require.Equal(byte(1), extendedP.Token(1)) | ||
require.Equal(byte(0), extendedP.Token(1)) | ||
require.Equal(byte(1), extendedP.Token(2)) | ||
require.Equal(byte(1), extendedP.Token(3)) | ||
require.Equal(byte(1), extendedP.Token(4)) | ||
require.Equal(byte(1), extendedP.Token(5)) | ||
|
||
path256 := NewPath([]byte{0b0000_0001}, BranchFactor256) | ||
p = NewPath([]byte{0b0000_0001}, BranchFactor256) | ||
extendedP = path256.Extend(p) | ||
require.Equal([]byte{0b0000_0001, 0b0000_0001}, extendedP.Bytes()) | ||
extendedP = path256.AppendExtend(0, p) | ||
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. Can we add tests where we don't pass 0? 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. It is covered in fuzz |
||
require.Equal([]byte{0b0000_0001, 0b0000_0000, 0b0000_0001}, extendedP.Bytes()) | ||
require.Equal(byte(1), extendedP.Token(0)) | ||
require.Equal(byte(1), extendedP.Token(1)) | ||
require.Equal(byte(0), extendedP.Token(1)) | ||
require.Equal(byte(1), extendedP.Token(2)) | ||
} | ||
|
||
func TestPathBytesNeeded(t *testing.T) { | ||
|
@@ -458,11 +464,12 @@ func TestPathBytesNeeded(t *testing.T) { | |
} | ||
} | ||
|
||
func FuzzPathExtend(f *testing.F) { | ||
func FuzzPathAppendExtend(f *testing.F) { | ||
f.Fuzz(func( | ||
t *testing.T, | ||
first []byte, | ||
second []byte, | ||
token byte, | ||
forceFirstOdd bool, | ||
forceSecondOdd bool, | ||
) { | ||
|
@@ -476,13 +483,15 @@ func FuzzPathExtend(f *testing.F) { | |
if forceSecondOdd && path2.tokensLength > 0 { | ||
path2 = path2.Take(path2.tokensLength - 1) | ||
} | ||
extendedP := path1.Extend(path2) | ||
require.Equal(path1.tokensLength+path2.tokensLength, extendedP.tokensLength) | ||
token = byte(int(token) % int(branchFactor)) | ||
extendedP := path1.AppendExtend(token, path2) | ||
require.Equal(path1.tokensLength+path2.tokensLength+1, extendedP.tokensLength) | ||
for i := 0; i < path1.tokensLength; i++ { | ||
require.Equal(path1.Token(i), extendedP.Token(i)) | ||
} | ||
require.Equal(token, extendedP.Token(path1.tokensLength)) | ||
for i := 0; i < path2.tokensLength; i++ { | ||
require.Equal(path2.Token(i), extendedP.Token(i+path1.tokensLength)) | ||
require.Equal(path2.Token(i), extendedP.Token(i+1+path1.tokensLength)) | ||
} | ||
} | ||
}) | ||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer just
Extend