[WIP] feat: elias-fano encoding - #9504
Draft
rapour wants to merge 2 commits into
Draft
Conversation
Signed-off-by: rapour <reza.apour@gmail.com>
Contributor
There was a problem hiding this comment.
can we try and make a mod out of all EF specific stuff so that I it would be easy to pull it into a external lib
rapour
marked this pull request as draft
August 20, 2026 12:15
Signed-off-by: rapour <reza.apour@gmail.com>
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.
Rationale for this change
This PR introduces a new encoding: Non-partitioned Elias-Fano for weakly monotonic sequences. The changes include the encoding itself plus a set of Reduce rules and kernels.
What changes are included in this PR?
The following decisions, subject to further discussion, have affected the implementation:
Non-partitioned only. The partitioned/quasi-succinct variant is left out entirely for the sake of simplicity. It can be added later.
Non-nullable. Currently the implementation only accepts non-nullable sequences. We can probably switch to accept them and persist a third validity buffer.
Sampled select rather than a full rank/select directory. The encoder stores the absolute position of every 256th set bit and every 512th unset bit, so a lookup jumps to the nearest signpost and finishes with a popcount walk bounded to one or two 64-byte blocks, for well under half a bit per value. We can switch to more complex rand/select directories based solutions like
RsVecbut the performance trade-offs needs investigation.An Elias-Fano array is encoded once, over a whole sequence, and every position inside it is absolute: element 500's bits sit at a fixed place in the buffers no matter which part of the array you are looking at. first_rank is just the offset saying which element of that original sequence this array's row 0 corresponds to. So slicing 1000..2000 out of a million-element array copies nothing. It sets first_rank = 1000 and the length to 1000, and reuses the original buffers unchanged; reading row 0 of the slice reads element 1000 underneath, row 1 reads element 1001, and so on. The trade-off is that the slice still carries the entire encoded sequence, in memory and on disk. Those unused rows only go away when the array is written out again.
The change implements a stateful cursor. The cursor remembers where it last stopped: the bit position, rank, and value of the element it just read, plus the last
next_geqanswer and, once enough reads land in one FastLanes block, that block unpacked. When the next probe is the same element or the one after it, reading is a step to the next set bit rather than a sampled select, so an ascending stream of probes (a list-offset scan, a merge join, a sorted selection vector) touches neither sample table, and clustered low-bits reads switch to one bulk unpack after the ninth hit in a block instead of paying a single-value unpack each time. A probe that lands somewhere unrelated just falls back to the normal sampled select, so the state never costs anything, which is why take, filter, and compare all open one cursor for the whole batch rather than one per row.One 64-bit path serves every integer width. Each value widens to
u64on the way in and has the reference subtracted; on the way out the reference is added back and the result narrows to the column's own width. Both steps use wrapping arithmetic, which is what makes them exact for signed columns as well as unsigned, soi8throughu64share one encoder, cursor, and decoder instead of getting one each. The column's type is consulted only at those two edges, so nothing in the per-element loop branches on it.What APIs are changed? Are there any user-facing changes?
Additive only. New crate
vortex-elias-fano(encodings/elias-fano), re-exported asvortex::encodings::elias_fano, exportingEliasFano,EliasFanoArray,EliasFanoData,EliasFanoMetadata,EliasFanoSlots,EliasFanoArraySlotsExt,EliasFanoCursor,elias_fano_encode, andinitialize.vortex-buffergainsBitBuffer::select_rangeandBitBuffer::select_zero_range; existingselectbehaviour is unchanged and the shared internalsstay crate-private.
No behaviour changes.
register_default_encodingsregisters the encoding, sovortex.elias_fanois readable with no feature flag, but nothing selects it: there is no compressor scheme yet and the
encoding is not a member of any edition, so files written by default sessions are byte-identical to
before. Applying it means calling
elias_fano_encodeexplicitly. Compressor selection and editionmembership follow separately.
Disclosure:
Claude code has implemented parts of the code, specially vortex-specific handles, comments, and tests, and improved others and has reviewed the implementation multiple times.