-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify logic for growing single group table.
Instead of swapping first and second halves, we just shift elements by 1. That algorithm derives "random" order from the previous state and leave a freedom for new element to be added at the beginning or at the end. For tables resizing from capacity 1 to 3, the logic is practically unchanged (although we remove 0 size memcpy). For tables resizing from capacity 3 to 7 1. Original order `012S`. 2. Old algorithm order: `2E01EEES` 3. New algorithm order: `E012EEES` Adding the forth element at the beginning or at the end with ~50% probability will add enough randomization. Benefits: 1. Simplify and speed up `GrowIntoSingleGroupShuffleControlBytes`. On ARM we just have two store operations. 2. `GrowIntoSingleGroupShuffleTransferableSlots` would become a single memcpy (instead of 2) that is faster. 3. `GrowSizeIntoSingleGroup` for non transferable objects is a bit simpler and moving data in order. On x86. ``` name old cpu/op new cpu/op delta BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:1 20.1ns ± 2% 20.2ns ± 1% +0.30% (p=0.002 n=63+67) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:2 23.2ns ± 1% 23.3ns ± 1% +0.43% (p=0.000 n=71+61) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:4 23.3ns ± 2% 22.5ns ± 1% -3.37% (p=0.000 n=68+63) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:8 20.5ns ± 2% 19.5ns ± 1% -4.79% (p=0.000 n=66+67) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:16 20.7ns ± 2% 20.3ns ± 2% -1.60% (p=0.000 n=70+67) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:32 19.1ns ± 2% 19.5ns ± 3% +1.86% (p=0.000 n=69+76) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:1 44.0ns ± 2% 44.0ns ± 1% ~ (p=0.673 n=67+63) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:2 39.6ns ± 2% 37.6ns ± 1% -5.01% (p=0.000 n=65+62) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:4 32.4ns ± 1% 30.3ns ± 1% -6.56% (p=0.000 n=64+62) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:8 26.1ns ± 1% 24.3ns ± 2% -6.91% (p=0.000 n=67+63) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:16 24.0ns ± 2% 23.4ns ± 2% -2.56% (p=0.000 n=64+64) ``` On ARM: ``` name old cpu/op new cpu/op delta BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:1 18.3ns ± 1% 18.4ns ± 1% ~ (p=0.059 n=76+77) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:2 24.7ns ± 0% 24.6ns ± 0% ~ (p=0.719 n=65+59) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:4 23.2ns ± 2% 22.6ns ± 0% -2.81% (p=0.000 n=71+51) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:8 21.7ns ± 2% 21.4ns ± 1% -1.36% (p=0.000 n=76+50) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:16 19.9ns ± 2% 19.7ns ± 1% -1.03% (p=0.000 n=75+65) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:1 45.5ns ± 1% 45.6ns ± 1% +0.36% (p=0.000 n=58+59) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:2 39.3ns ± 1% 38.3ns ± 1% -2.54% (p=0.000 n=63+60) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:4 31.6ns ± 2% 30.0ns ± 2% -4.99% (p=0.000 n=76+73) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:8 26.4ns ± 2% 25.6ns ± 2% -3.00% (p=0.000 n=73+66) BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 64>/set_size:16 23.1ns ± 2% 22.7ns ± 1% -1.92% (p=0.000 n=67+64) ``` PiperOrigin-RevId: 702065961 Change-Id: I725475815e017a29384a733f73717050c3aad5b8
- Loading branch information
1 parent
95950b3
commit a04ef10
Showing
2 changed files
with
122 additions
and
131 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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