|
| 1 | +# Report |
| 2 | + |
| 3 | +Compares the **legacy** sketch implementations in `sketch-core` vs the **asap_sketchlib** backends (Count-Min Sketch, Count-Min-With-Heap, KLL, HydraKLL). |
| 4 | + |
| 5 | +## Fidelity harness |
| 6 | + |
| 7 | +The fidelity binary selects backends via CLI flags (`--cms-impl`, `--kll-impl`, `--cmwh-impl`). |
| 8 | + |
| 9 | +| Goal | Command | |
| 10 | +|--------------------------|--------------------------------------------------------------------------------------------------------------| |
| 11 | +| Default (all sketchlib) | `cargo run -p sketch-core --bin sketchlib_fidelity` | |
| 12 | +| All legacy | `cargo run -p sketch-core --bin sketchlib_fidelity -- --cms-impl legacy --kll-impl legacy --cmwh-impl legacy` | |
| 13 | +| Legacy KLL only | `cargo run -p sketch-core --bin sketchlib_fidelity -- --cms-impl sketchlib --kll-impl legacy --cmwh-impl sketchlib` | |
| 14 | +| CMS sketchlib only | `cargo run -p sketch-core --bin sketchlib_fidelity -- --cms-impl sketchlib` | |
| 15 | +| CMS legacy only | `cargo run -p sketch-core --bin sketchlib_fidelity -- --cms-impl legacy` | |
| 16 | + |
| 17 | +## Unit tests |
| 18 | + |
| 19 | +Unit tests always run with **legacy** backends enabled (the test ctor calls |
| 20 | +`force_legacy_mode_for_tests()`), so you only need: |
| 21 | + |
| 22 | +```bash |
| 23 | +cargo test -p sketch-core |
| 24 | +``` |
| 25 | + |
| 26 | +## Results |
| 27 | + |
| 28 | +### CountMinSketch (accuracy vs exact counts) |
| 29 | + |
| 30 | +#### depth=3 |
| 31 | + |
| 32 | +| width | n | domain | Mode | Pearson corr | MAPE (%) | RMSE (%) | |
| 33 | +|-------|--------|--------|----------------|----------------|----------|----------| |
| 34 | +| 1024 | 100000 | 1000 | Legacy | 0.9998451189 | 24.48 | 52.76 | |
| 35 | +| 1024 | 100000 | 1000 | asap_sketchlib | 0.9998387103 | 24.36 | 54.11 | |
| 36 | + |
| 37 | +#### depth=5 |
| 38 | + |
| 39 | +| width | n | domain | Mode | Pearson corr | MAPE (%) | RMSE (%) | |
| 40 | +|-------|--------|--------|----------------|----------------|----------|----------| |
| 41 | +| 2048 | 200000 | 2000 | Legacy | 0.9999733814 | 8.75 | 29.94 | |
| 42 | +| 2048 | 200000 | 2000 | asap_sketchlib | 0.9999744627 | 8.37 | 28.84 | |
| 43 | +| 2048 | 50000 | 500 | Legacy | 1.0000000000 | 0.00 | 0.00 | |
| 44 | +| 2048 | 50000 | 500 | asap_sketchlib | 1.0000000000 | 0.00 | 0.00 | |
| 45 | + |
| 46 | +#### depth=7 |
| 47 | + |
| 48 | +| width | n | domain | Mode | Pearson corr | MAPE (%) | RMSE (%) | |
| 49 | +|-------|--------|--------|----------------|----------------|----------|----------| |
| 50 | +| 4096 | 200000 | 2000 | Legacy | 0.9999993694 | 0.20 | 3.69 | |
| 51 | +| 4096 | 200000 | 2000 | asap_sketchlib | 0.9999993499 | 0.21 | 4.27 | |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +### CountMinSketchWithHeap (top-k + CMS accuracy on exact top-k) |
| 56 | + |
| 57 | +The heap is maintained by local updates; recall is measured against the **true** top-k at the end of the stream. |
| 58 | + |
| 59 | +#### depth=3 |
| 60 | + |
| 61 | +| width | n | domain | heap_size | Mode | Top-k recall | Pearson (top-k) | MAPE (%) | RMSE (%) | |
| 62 | +|-------|--------|--------|-----------|----------------|--------------|-----------------|----------|----------| |
| 63 | +| 1024 | 100000 | 1000 | 10 | Legacy | 0.40 | 0.9571 | 0.174 | 0.319 | |
| 64 | +| 1024 | 100000 | 1000 | 10 | asap_sketchlib | 0.80 | 1.0000 | 0.000 | 0.000 | |
| 65 | + |
| 66 | +#### depth=5 |
| 67 | + |
| 68 | +| width | n | domain | heap_size | Mode | Top-k recall | Pearson (top-k) | MAPE (%) | RMSE (%) | |
| 69 | +|-------|--------|--------|-----------|----------------|--------------|-----------------|----------|----------| |
| 70 | +| 2048 | 200000 | 2000 | 20 | Legacy | 0.60 | 0.9964 | 0.045 | 0.101 | |
| 71 | +| 2048 | 200000 | 2000 | 20 | asap_sketchlib | 1.00 | 0.9982 | 0.021 | 0.067 | |
| 72 | +| 2048 | 200000 | 2000 | 50 | Legacy | 0.40 | 0.9999983 | 5.60 | 16.49 | |
| 73 | +| 2048 | 200000 | 2000 | 50 | asap_sketchlib | 0.48 | 0.9999990 | 3.90 | 12.95 | |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +### KllSketch (quantiles, absolute rank error) |
| 78 | + |
| 79 | +For each quantile \(q\), we compute the sketch estimate `est_value`, then: |
| 80 | +`abs_rank_error = |rank_fraction(exact_sorted_values, est_value) - q|`. |
| 81 | + |
| 82 | +#### k=20 |
| 83 | + |
| 84 | +| n_updates | Mode | q=0.5 | q=0.9 | q=0.99 | |
| 85 | +|-----------|----------------|---------|---------|---------| |
| 86 | +| 200000 | Legacy | 0.0104 | 0.0145 | 0.0028 | |
| 87 | +| 200000 | asap_sketchlib | 0.0275 | 0.0470 | 0.0061 | |
| 88 | +| 50000 | Legacy | 0.0131 | 0.0091 | 0.0054 | |
| 89 | +| 50000 | asap_sketchlib | 0.0110 | 0.0116 | 0.0031 | |
| 90 | + |
| 91 | +#### k=50 |
| 92 | + |
| 93 | +| n_updates | Mode | q=0.5 | q=0.9 | q=0.99 | |
| 94 | +|-----------|----------------|---------|---------|---------| |
| 95 | +| 200000 | Legacy | 0.0013 | 0.0021 | 0.0012 | |
| 96 | +| 200000 | asap_sketchlib | 0.0101 | 0.0044 | 0.0074 | |
| 97 | + |
| 98 | +#### k=200 |
| 99 | + |
| 100 | +| n_updates | Mode | q=0.5 | q=0.9 | q=0.99 | |
| 101 | +|-----------|----------------|---------|---------|---------| |
| 102 | +| 200000 | Legacy | 0.0021 | 0.0036 | 0.0000 | |
| 103 | +| 200000 | asap_sketchlib | 0.0015 | 0.0001 | 0.0002 | |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +### HydraKllSketch (per-key quantiles, mean/max absolute rank error across 50 keys) |
| 108 | + |
| 109 | +#### rows=2, cols=64 |
| 110 | + |
| 111 | +| k | n | domain | Mode | q=0.5 (mean / max) | q=0.9 (mean / max) | |
| 112 | +|-----|--------|--------|----------------|--------------------|--------------------| |
| 113 | +| 20 | 200000 | 200 | Legacy | 0.0170 / 0.0546 | 0.0165 / 0.0452 | |
| 114 | +| 20 | 200000 | 200 | asap_sketchlib | 0.0254 / 0.0629 | 0.0546 / 0.0942 | |
| 115 | + |
| 116 | +#### rows=3, cols=128 |
| 117 | + |
| 118 | +| k | n | domain | Mode | q=0.5 (mean / max) | q=0.9 (mean / max) | |
| 119 | +|-----|--------|--------|----------------|--------------------|--------------------| |
| 120 | +| 20 | 200000 | 200 | Legacy | 0.0166 / 0.0591 | 0.0114 / 0.0304 | |
| 121 | +| 20 | 200000 | 200 | asap_sketchlib | 0.0216 / 0.0534 | 0.0238 / 0.1087 | |
| 122 | +| 50 | 200000 | 200 | Legacy | 0.0099 / 0.0352 | 0.0087 / 0.0330 | |
| 123 | +| 50 | 200000 | 200 | asap_sketchlib | 0.0119 / 0.0458 | 0.0119 / 0.0296 | |
| 124 | +| 20 | 100000 | 100 | Legacy | 0.0141 / 0.0574 | 0.0149 / 0.0471 | |
| 125 | +| 20 | 100000 | 100 | asap_sketchlib | 0.0202 / 0.0621 | 0.0287 / 0.0779 | |
0 commit comments