-
Notifications
You must be signed in to change notification settings - Fork 111
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
Remove the repeated logic of the method that overwrites the lower nibble of container type descriptor. #548
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
... and 1 file with indirect coverage changes 📢 Thoughts on this report? Let us know! |
// XXX we'll never overrun a block unless we're given a position past our block array | ||
final Block block = blocks.get(index); | ||
block.data[offset] = (byte) value; | ||
long bitValue = block.data[offset]; | ||
if (value <= 0xD) { |
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 suggest creating a new method (something like 'writeLowerNibbleAt'), and call it for this purpose, instead of branching within this method.
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
…ble of container type descriptor.
…d under 'writeUInt8At'.
336a846
to
0769dc0
Compare
…ble of container type descriptor. (#548)
Issue #, if available:
N/A
Description of changes:
This PR optimize the process of overwriting lower nibble of type descriptor by avoid unnecessary method calls:
Context:
While writing containers, if the container length is small enough to fit in the lower nibble of the type descriptor byte, we will overwrite the lower nibble of the type descriptor byte with encoded length.
Before change, we need to use method
buffer.getUInt8At ()
to calculate the OCTET of the type descriptor then combine it with the length value and then write the value to buffer by usingbuffer.writeVarUInt8At()
. Both of these methods including calculationsindex = index(position)
,offset = offset(position)
. In this PR, we will pass the length value directly tobuffer.writeVarUInt8At()
to avoid repeated calculations ofindex
andoffset
.Here are the benchmark results before and after changes:
Results from benchmarking a write of data equivalent to a stream of 194617 nested binary Ion value(3 forks, 2 warmups, 2 iterations, preallocation 1).
Results from benchmarking a write of data equivalent to a stream of 59155 nested binary Ion values(3 forks, 2 warmups, 2 iterations, preallocation 1).
Results from benchmarking a write of data equivalent to a single nested binary Ion value(3 forks, 2 warmups, 2 iterations, preallocation 1).
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.