-
Notifications
You must be signed in to change notification settings - Fork 140
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 HashInput functions to use scratch buffer provided by onflow/atree #1296
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1296 +/- ##
==========================================
+ Coverage 77.39% 77.41% +0.01%
==========================================
Files 279 279
Lines 36048 36113 +65
==========================================
+ Hits 27899 27956 +57
- Misses 7062 7066 +4
- Partials 1087 1091 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Cadence Benchstat comparisonThis branch with compared with the base branch onflow:master commit 651817e Results
|
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.
Nice! Thank you for optimizing this 👍
if length <= len(scratch) { | ||
buf = scratch[:length] | ||
} else { | ||
buf = make([]byte, length) | ||
} |
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.
Good idea!
// HashInput returns a byte slice containing: | ||
// - HashInputTypeInt8 (1 byte) | ||
// - int8 value (1 byte) |
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.
Thank you for also adding comments to the unchanged functions 👍
@fxamacker It looks like coverage went down as the new cases where the input does not fit into the scratch are not covered by tests (e.g. https://app.codecov.io/gh/onflow/cadence/compare/1296/tree/runtime/interpreter/value.go#D1L352). Could you please add some tests with longer/larger values? Thank you! |
Yikes! Thanks for catching this! 👍 It would've been bad to merge with this mistake. I added more tests. Many thanks! |
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.
Nice!
@@ -1116,82 +1118,242 @@ func TestGetHashInput(t *testing.T) { | |||
value: NewUIntValueFromUint64(10), | |||
expected: []byte{byte(HashInputTypeUInt), 10}, | |||
}, | |||
"UInt min": { |
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.
Great idea to use min & max values 👍
Closes #1258
Description
Optimize
HashInput
functions to use a small scratch buffer provided by onflow/atree.master
branchFiles changed
in the Github PR explorer