Optimize BucketingInputSource for performance #1273
Merged
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.
The BucketingInputSource has a bytePositionToIndicies function that returns a tuple containing the bucket index and index within that bucket to find a given byte position. This function should be inlined and in theory the tuple allocation could be optimized out since we immediately take it apart into separate variables, but that doesn't seem to be the case, and leads to noticeable Overhead.
This removes the tuple allocation by replacing the one function with two separate functions. This means there is now an extra function call but it avoids the tuple allocation, which appears to be the main overhead.
This also is more careful about which variables are Int's and Long's to minimize the number of toInt calls. This is unlikely to make a performance difference, but does make the code cleaner. This also switches from integer/modular division to shifts and masks which should also be more efficient. This does now require the bucket size to be specified as a power of two.
In basic testing, these changes reduced the overhead of the BucketingInputSource compared to the ByteBufferInputSource from about 15% to 5%.
DAFFODIL-2920