Commit fe388a0
authored
More robust types in the compressor (#7415)
## Summary
Tracking issue: #7216
Makes the compressor types more robust (removes the possibility for
invalid state), which additionally sets up adding tracing easier (draft
at #7385)
## API Changes
Changes some types:
```rust
/// Closure type for [`DeferredEstimate::Callback`].
///
/// The compressor calls this with the same arguments it would pass to sampling. The closure must
/// resolve directly to a terminal [`EstimateVerdict`].
#[rustfmt::skip]
pub type EstimateFn = dyn FnOnce(
&CascadingCompressor,
&mut ArrayAndStats,
CompressorContext,
) -> VortexResult<EstimateVerdict>
+ Send
+ Sync;
/// The result of a [`Scheme`]'s compression ratio estimation.
///
/// This type is returned by [`Scheme::expected_compression_ratio`] to tell the compressor how
/// promising this scheme is for a given array without performing any expensive work.
///
/// [`CompressionEstimate::Verdict`] means the scheme already knows the terminal answer.
/// [`CompressionEstimate::Deferred`] means the compressor must do extra work before the scheme can
/// produce a terminal answer.
#[derive(Debug)]
pub enum CompressionEstimate {
/// The scheme already knows the terminal estimation verdict.
Verdict(EstimateVerdict),
/// The compressor must perform deferred work to resolve the terminal estimation verdict.
Deferred(DeferredEstimate),
}
/// The terminal answer to a compression estimate request.
#[derive(Debug)]
pub enum EstimateVerdict {
/// Do not use this scheme for this array.
Skip,
/// Always use this scheme, as it is definitively the best choice.
///
/// Some examples include constant detection, decimal byte parts, and temporal decomposition.
///
/// The compressor will select this scheme immediately without evaluating further candidates.
/// Schemes that return `AlwaysUse` must be mutually exclusive per canonical type (enforced by
/// [`Scheme::matches`]), otherwise the winner depends silently on registration order.
///
/// [`Scheme::matches`]: crate::scheme::Scheme::matches
AlwaysUse,
/// The estimated compression ratio. This must be greater than `1.0` to be considered by the
/// compressor, otherwise it is worse than the canonical encoding.
Ratio(f64),
}
/// Deferred work that can resolve to a terminal [`EstimateVerdict`].
pub enum DeferredEstimate {
/// The scheme cannot cheaply estimate its ratio, so the compressor should compress a small
/// sample to determine effectiveness.
Sample,
/// A fallible estimation requiring a custom expensive computation.
///
/// Use this only when the scheme needs to perform trial encoding or other costly checks to
/// determine its compression ratio. The callback returns an [`EstimateVerdict`] directly, so
/// it cannot request more sampling or another deferred callback.
Callback(Box<EstimateFn>),
}
```
This will make some changes that we want to make is the future easier as
well (tracing, better decision making for what things to try, etc).
## Testing
Some new tests
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>1 parent 71089dd commit fe388a0
17 files changed
Lines changed: 494 additions & 175 deletions
File tree
- vortex-btrblocks/src/schemes
- vortex-compressor
- src
- builtins
- constant
- dict
- vortex-tensor/src/encodings/turboquant
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
91 | | - | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
96 | | - | |
| 98 | + | |
97 | 99 | | |
98 | 100 | | |
99 | | - | |
| 101 | + | |
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| |||
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
157 | | - | |
| 159 | + | |
158 | 160 | | |
159 | 161 | | |
160 | | - | |
| 162 | + | |
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
| |||
225 | 227 | | |
226 | 228 | | |
227 | 229 | | |
228 | | - | |
| 230 | + | |
229 | 231 | | |
230 | 232 | | |
231 | 233 | | |
232 | 234 | | |
233 | | - | |
| 235 | + | |
234 | 236 | | |
235 | 237 | | |
236 | 238 | | |
237 | | - | |
| 239 | + | |
238 | 240 | | |
239 | 241 | | |
240 | 242 | | |
| |||
279 | 281 | | |
280 | 282 | | |
281 | 283 | | |
282 | | - | |
| 284 | + | |
283 | 285 | | |
284 | 286 | | |
285 | 287 | | |
| |||
326 | 328 | | |
327 | 329 | | |
328 | 330 | | |
329 | | - | |
| 331 | + | |
330 | 332 | | |
331 | 333 | | |
332 | 334 | | |
333 | | - | |
| 335 | + | |
334 | 336 | | |
335 | 337 | | |
336 | | - | |
| 338 | + | |
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
137 | | - | |
| 139 | + | |
138 | 140 | | |
139 | 141 | | |
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
143 | 145 | | |
144 | | - | |
| 146 | + | |
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
151 | | - | |
| 153 | + | |
152 | 154 | | |
153 | 155 | | |
154 | 156 | | |
| |||
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
165 | | - | |
| 167 | + | |
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
| |||
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
176 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
| |||
265 | 269 | | |
266 | 270 | | |
267 | 271 | | |
268 | | - | |
| 272 | + | |
269 | 273 | | |
270 | 274 | | |
271 | 275 | | |
272 | 276 | | |
273 | 277 | | |
274 | 278 | | |
275 | | - | |
| 279 | + | |
276 | 280 | | |
277 | 281 | | |
278 | | - | |
| 282 | + | |
279 | 283 | | |
280 | 284 | | |
281 | 285 | | |
| |||
314 | 318 | | |
315 | 319 | | |
316 | 320 | | |
317 | | - | |
| 321 | + | |
318 | 322 | | |
319 | 323 | | |
320 | | - | |
| 324 | + | |
321 | 325 | | |
322 | 326 | | |
323 | 327 | | |
| |||
443 | 447 | | |
444 | 448 | | |
445 | 449 | | |
446 | | - | |
| 450 | + | |
447 | 451 | | |
448 | 452 | | |
449 | 453 | | |
450 | 454 | | |
451 | | - | |
| 455 | + | |
452 | 456 | | |
453 | 457 | | |
454 | 458 | | |
| |||
460 | 464 | | |
461 | 465 | | |
462 | 466 | | |
463 | | - | |
| 467 | + | |
464 | 468 | | |
465 | 469 | | |
466 | 470 | | |
467 | 471 | | |
468 | 472 | | |
469 | 473 | | |
470 | | - | |
| 474 | + | |
471 | 475 | | |
472 | 476 | | |
473 | 477 | | |
474 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
475 | 481 | | |
476 | 482 | | |
477 | 483 | | |
| |||
603 | 609 | | |
604 | 610 | | |
605 | 611 | | |
606 | | - | |
| 612 | + | |
607 | 613 | | |
608 | 614 | | |
609 | | - | |
| 615 | + | |
610 | 616 | | |
611 | 617 | | |
612 | 618 | | |
| |||
668 | 674 | | |
669 | 675 | | |
670 | 676 | | |
671 | | - | |
| 677 | + | |
672 | 678 | | |
673 | 679 | | |
674 | 680 | | |
675 | 681 | | |
676 | 682 | | |
677 | 683 | | |
678 | | - | |
| 684 | + | |
679 | 685 | | |
680 | 686 | | |
681 | 687 | | |
| |||
684 | 690 | | |
685 | 691 | | |
686 | 692 | | |
687 | | - | |
| 693 | + | |
688 | 694 | | |
689 | 695 | | |
690 | 696 | | |
691 | 697 | | |
692 | 698 | | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
704 | 712 | | |
705 | 713 | | |
706 | 714 | | |
| |||
738 | 746 | | |
739 | 747 | | |
740 | 748 | | |
741 | | - | |
| 749 | + | |
742 | 750 | | |
743 | 751 | | |
744 | | - | |
| 752 | + | |
745 | 753 | | |
746 | 754 | | |
747 | 755 | | |
| |||
865 | 873 | | |
866 | 874 | | |
867 | 875 | | |
868 | | - | |
| 876 | + | |
869 | 877 | | |
870 | 878 | | |
871 | 879 | | |
872 | | - | |
| 880 | + | |
873 | 881 | | |
874 | 882 | | |
875 | | - | |
| 883 | + | |
876 | 884 | | |
877 | 885 | | |
878 | 886 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
76 | | - | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
164 | | - | |
| 166 | + | |
165 | 167 | | |
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
169 | | - | |
| 171 | + | |
170 | 172 | | |
171 | 173 | | |
172 | 174 | | |
173 | | - | |
| 175 | + | |
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
| |||
216 | 218 | | |
217 | 219 | | |
218 | 220 | | |
219 | | - | |
| 221 | + | |
220 | 222 | | |
221 | 223 | | |
222 | 224 | | |
| |||
245 | 247 | | |
246 | 248 | | |
247 | 249 | | |
248 | | - | |
| 250 | + | |
249 | 251 | | |
250 | 252 | | |
251 | 253 | | |
| |||
0 commit comments