Commit 069f29d
authored
feat(bitpacking): Add batched index unpacking (#190)
Add `unpack_indices` and `unchecked_unpack_indices` to extract selected
values without a complete 1,024-value unpack.
Use `unpack_indices` when the bit width and packed length are
compile-time constants. Use `unchecked_unpack_indices` when the bit
width is available only at runtime. It dispatches the runtime width once
per batch.
Both methods write into `MaybeUninit` output. Use `unpack_single` for
one selected value. Use full unpack above the recommended threshold.
One private `#[inline(always)]` helper implements single-value
extraction. Public `unpack_single` keeps an out-of-line boundary. The
runtime dispatcher and batch path inline the helper after width
dispatch. This keeps width-specific expansion inside library code.
## Performance
Native Apple M1 benchmarks use Rust 1.91.0 and `-C target-cpu=native`.
At 8 and 32 selected values, batch extraction is 2.0–3.4× faster than
repeated `unpack_single` calls.
The table gives a conservative dispatch policy across the sampled packed
widths.
| Physical type | Use batch when | Use full unpack when |
| --- | ---: | ---: |
| `u8` | `n <= 16` | `n > 16` |
| `u16` | `n <= 32` | `n > 32` |
| `u32` | `n <= 64` | `n > 64` |
| `u64` | `n <= 160` | `n > 160` |
The grid covers widths 1, 4, and 7 for `u8`. It covers widths 1, 3, 8,
and 15 for `u16`.
It covers widths 1, 8, 16, 24, and 31 for `u32`. It covers widths 1, 16,
32, 48, and 63 for `u64`.
The limiting measured crossovers were 18–19, 32–34, 68–72, and 176–184.
The rounded thresholds leave margin for other hardware.
Packed-width effects were non-monotonic, so the policy uses only the
physical type and selected-value count.
`cargo asm` confirms one runtime-width dispatch per batch. The generated
`u16` batch function contains no per-index `unpack_single` calls.
## Code size
The release rlib grows from 3,750,536 bytes on `develop` to 3,942,416
bytes, a 5.1% increase. Object text grows from 419,814 bytes to 447,917
bytes, a 6.7% increase.
## Verification
Tests cover every integer type and runtime width. They also cover empty,
duplicate, unordered, full-block, zero-width, and invalid inputs.
🤖 Generated with [Codex](https://openai.com/codex/)
---------
Signed-off-by: Will Manning <will@willmanning.io>1 parent 6e2aaa6 commit 069f29d
2 files changed
Lines changed: 377 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
93 | 233 | | |
94 | 234 | | |
95 | 235 | | |
| |||
0 commit comments