Set the default preallocation mode of binary IonWriter to 1.#481
Merged
Set the default preallocation mode of binary IonWriter to 1.#481
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #481 +/- ##
============================================
- Coverage 66.84% 66.82% -0.02%
- Complexity 5417 5419 +2
============================================
Files 156 156
Lines 22728 22728
Branches 4087 4087
============================================
- Hits 15193 15189 -4
- Misses 6240 6242 +2
- Partials 1295 1297 +2
... and 2 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue #, if available:
According to issue #421
Description of changes:
Motivation:
Now that 1-byte preallocation does not result in a data size penalty (#401), changing the default preallocation mode from 0 to 1 can improve binary write performance without inflating the encoding.
When the container length is:
< 14:The body of this container/wrapper is small enough that its length can fit in the lower nibble of the type descriptor byte; we don't need the extra
1byte that was preallocated. Shift the encoded body of the container/wrapper backwards in the buffer to reclaim the extra1byte. The action of shift back will usually be a very fast memcpy.>= 14 and < 128:The container's encoded body is too long to fit the length in the type descriptor byte, but it will fit in the preallocated length byte that was added to the buffer when the container was started. Update that bytes with the
VarUIntencoding of the length value. In this case, Ion binary writing will enjoy the speed boost from preallocation.>= 128:The container's encoded body is too long to fit in the length byte that was preallocated. We will use
PatchPointto write theVarUIntencoding of the length in a secondary buffer and include that data when we flush the primary buffer to the output stream.Here are the benchmark results which indicate the speed boost:
The binary IonWriter using preallocation mode
1shows 16.58% faster for datasetlog.10ncomparing to binary IonWriter with default preallocation mode0.Full results here.
The binary IonWriter using preallocation mode
1shows 6.28% faster for datasetitem.10ncomparing to binary IonWriter with default preallocation mode0.Full results here.
The binary IonWriter using preallocation mode
1shows 11.11% faster for datasetevent.10ncomparing to binary IonWriter with default preallocation mode0.Full results here.
The binary IonWriter using preallocation mode
1shows 16.27% faster for datasetcomplex.10ncomparing to binary IonWriter with default preallocation mode0.Full results here.
Why set the default to 1 instead of 2?
According to the performance benchmark results, when we set the preallocation mode to 2, performance is even better. However, extra preallocated space is not reclaimed in this case when containers are >= 14 and < 128 bytes, which might causes the serialized size to inflate. Setting the default to 1 for now avoids that tradeoff.
Next step:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.