[2/n] use a slab-based impl for ItemSet#243
Open
sunshowers wants to merge 4 commits intosunshowers/spr/main.2n-use-a-slab-based-impl-for-itemsetfrom
Open
[2/n] use a slab-based impl for ItemSet#243sunshowers wants to merge 4 commits intosunshowers/spr/main.2n-use-a-slab-based-impl-for-itemsetfrom
sunshowers wants to merge 4 commits intosunshowers/spr/main.2n-use-a-slab-based-impl-for-itemsetfrom
Conversation
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
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.
The motivation is that a vec is significantly more efficient than a hash table
at storing compact and compact-ish integer keys, as the benchmark data below
shows.
We use a slab-based implementation, i.e.
Vec<SlabEntry<T>>, whereSlabEntry<T>is an enum withOccupied(T)andVacant { next: ItemIndex }variants. The
Vacantentries form an embedded free chain, so thatinserts reuse vacant slots without any secondary allocation.
We also change
shrink_to_fitto compact the slab and rewrite internalindexes.
Delta vs. the HashMap-backed
ItemSetfrom the previous commit(criterion median percent change; −N% is faster, +N% is slower):
Overall, this is a pretty nice win throughout! There are a few anomalies at large sizes that are best explained by L1 cache overflow, but in general we're up to 3x as fast as before, and significantly more competitive with the std maps, including being faster at a few things like bulk insert and iteration. (As a bonus, we also get to drop the rustc-hash dependency.)