[Dev] Optimize ValidityMask when reading from a ColumnDataCollection#14416
Merged
Mytherin merged 1 commit intoduckdb:featurefrom Oct 19, 2024
Merged
Conversation
hawkfish
reviewed
Oct 17, 2024
| } | ||
| } | ||
| if ((count % ValidityMask::BITS_PER_VALUE) != 0) { | ||
| auto entry = validity_mask[(count / ValidityMask::BITS_PER_VALUE)]; |
Contributor
There was a problem hiding this comment.
Maybe we could do this with a single bitwise operation?
Contributor
Author
There was a problem hiding this comment.
Hmm constructing the mask and then comparing against that in one go?
Contributor
There was a problem hiding this comment.
Yeah I was wondering if some kind of shifted mask comparison would work: entry & mask = mask. I think mask could be constructed from all bits shifted by the ragged count?
Contributor
|
Love this BTW - it may let me remove some bookkeeping in the window spooling logic. |
Collaborator
|
Thanks! LGTM |
Contributor
Author
|
I was quickly looking into the optimization that Richard recommended, will push that as a separate PR 👍 |
Mytherin
added a commit
that referenced
this pull request
Oct 20, 2024
This PR implements the suggestion made by [Richard](#14416 (comment)) When a `validity_t` is used for < `ValidityMask::BITS_PER_VALUE` values, the least significant bits are set, i.e if `ValidityMask::BITS_PER_VALUE` was 8 5 values uses : `xxx4 3210` For that we can construct the mask: `0001 1111` To check that all bits are set for those values Given that `ValidityMask::BITS_PER_VALUE` is 64, we save 1<=n<64 function calls by doing this
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.
When we serialize the ColumnDataCollection, we will write the
validity_t *validity_maskregardless of the validity being uninitialized or not.We do this because it's difficult to keep track of the validity status when appending multiple Vectors.
When we read this back however, we receive a ValidityMask that returns false for
AllValidwhich could be costly as most execution paths of the engine have optimized paths forAllValid()being true.Now we'll efficiently check the validity mask when reading and replace it will nullptr if all entries are valid, enabling the
AllValid() == trueoptimized path for these vectors.