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

Speed up seed generation from 494 ns/op to 3 ns/op #191

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.15

require (
github.com/fxamacker/cbor/v2 v2.2.1-0.20210927235116-3d6d5d1de29b
github.com/fxamacker/circlehash v0.0.2
github.com/fxamacker/circlehash v0.1.0
github.com/stretchr/testify v1.7.0
github.com/zeebo/blake3 v0.2.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fxamacker/cbor/v2 v2.2.1-0.20210927235116-3d6d5d1de29b h1:85oJb8jRevEXzzY3jtDas1Y5qw9iqsbOhdc5lH86vHs=
github.com/fxamacker/cbor/v2 v2.2.1-0.20210927235116-3d6d5d1de29b/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/fxamacker/circlehash v0.0.2 h1:69lo0MXfjBh4bHOtklI0rXTXj9FOiP949lW1YSWCNQE=
github.com/fxamacker/circlehash v0.0.2/go.mod h1:3aq3OfVvsWtkWMb6A1owjOQFA+TLsD5FgJflnaQwtMM=
github.com/fxamacker/circlehash v0.1.0 h1:wXK52nkcBzGM+FyYc3wFYshm+0523BfX7h1XsUJLl70=
github.com/fxamacker/circlehash v0.1.0/go.mod h1:3aq3OfVvsWtkWMb6A1owjOQFA+TLsD5FgJflnaQwtMM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
Expand Down
12 changes: 5 additions & 7 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -3326,12 +3326,6 @@ func NewMap(storage SlabStorage, address Address, digestBuilder DigesterBuilder,
return nil, NewStorageError(err)
}

sIDBytes := make([]byte, storageIDSize)
_, err = sID.ToRawBytes(sIDBytes)
if err != nil {
return nil, NewStorageError(err)
}

// Create seed for non-crypto hash algos (CircleHash64, SipHash) to use.
// Ideally, seed should be a nondeterministic 128-bit secret because
// these hashes rely on its key being secret for its security. Since
Expand All @@ -3340,7 +3334,11 @@ func NewMap(storage SlabStorage, address Address, digestBuilder DigesterBuilder,
// a 128-bit secret key. And for performance reasons, we first use
// noncrypto hash algos and fall back to crypto algo after collisions.
// This is for creating the seed, so the seed used here is OK to be 0.
k0 := circlehash.Hash64(sIDBytes, uint64(0))
// LittleEndian is needed for compatibility (same digest from []byte and
// two uint64).
a := binary.LittleEndian.Uint64(sID.Address[:])
b := binary.LittleEndian.Uint64(sID.Index[:])
k0 := circlehash.Hash64Uint64x2(a, b, uint64(0))

// To save storage space, only store 64-bits of the seed.
// Use a 64-bit const for the unstored half to create 128-bit seed.
Expand Down