Commit c5c9a38
Reimplement SmallMap (again)
Summary:
Change `VecMap` (which is linear part of `SmallMap`) from
```
Vec<(Hash, K, V)>
```
to
```
Vec2<(K, V), Hash>
```
The idea is this: hash is 32 bit. But because of padding, it occupies 64 bits. So by changing layout from
```
H, K, V, H, K, V, ....
```
to
```
K, V, K, V, ..., H, H, ...
```
we save 4 bytes per entry.
At cost of slower operations with `SmallMap`. However `SmallMap` is meant to be small, not fast, so this is probably acceptable.
Basically we trade 2% memory for 0.5% CPU.
Also, additional savings of memory are possible: because hashes are stored in contiguous memory now, we can use SIMD to scan them. So we can increase the amount of entries with scan linearly before allocating the index without hurting much performance (currently we create the index at 12 entries).
Also, we can now implement storing `RawTable` next to `Vec2` data, to reduce the size of empty `SmallMap` from 4 words to 3.
Reviewed By: ndmitchell
Differential Revision: D40557486
fbshipit-source-id: 44ef3dd8de0b72171fa084a417dbf7376c793bae1 parent 531cc29 commit c5c9a38
2 files changed
+431
-73
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| 25 | + | |
| 26 | + | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
25 | | - | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
28 | 37 | | |
29 | 38 | | |
30 | 39 | | |
| 40 | + | |
31 | 41 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
36 | 46 | | |
37 | 47 | | |
| 48 | + | |
38 | 49 | | |
39 | 50 | | |
40 | 51 | | |
41 | 52 | | |
42 | 53 | | |
43 | 54 | | |
| 55 | + | |
44 | 56 | | |
45 | 57 | | |
46 | 58 | | |
47 | 59 | | |
48 | 60 | | |
49 | 61 | | |
| 62 | + | |
50 | 63 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
55 | 67 | | |
56 | 68 | | |
57 | 69 | | |
58 | 70 | | |
59 | | - | |
60 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
61 | 77 | | |
62 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
63 | 82 | | |
64 | 83 | | |
65 | 84 | | |
| 85 | + | |
66 | 86 | | |
67 | | - | |
68 | | - | |
69 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
70 | 97 | | |
71 | 98 | | |
72 | 99 | | |
| 100 | + | |
73 | 101 | | |
74 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
75 | 115 | | |
76 | 116 | | |
77 | 117 | | |
78 | 118 | | |
| 119 | + | |
79 | 120 | | |
80 | | - | |
| 121 | + | |
81 | 122 | | |
82 | 123 | | |
83 | 124 | | |
84 | 125 | | |
85 | 126 | | |
86 | | - | |
87 | | - | |
88 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
89 | 136 | | |
90 | 137 | | |
91 | 138 | | |
0 commit comments