Skip to content

Commit ee172d6

Browse files
lwwmanningclaude
andcommitted
chore[turboquant]: cleanup from second simplify pass
- Use vortex_utils::aliases::dash_map::DashMap instead of raw dashmap, matching codebase convention (removes direct dashmap dependency) - Fix stale doc comment on gen_random_signs (leftover from deleted apply_inverse_srht_from_bits function) - Move function-scoped `use crate::rotation::RotationMatrix` to test module top per CLAUDE.md - Optimize hot loop: replace padded.fill(0.0) every row with conditional [..dim] zeroing only when norm==0. The tail [dim..padded_dim] is zeroed once at allocation and never overwritten, saving padded_dim×4 bytes of unnecessary stores per row. Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Will Manning <will@willmanning.io>
1 parent 2477685 commit ee172d6

6 files changed

Lines changed: 9 additions & 14 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

encodings/turboquant/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ version = { workspace = true }
1717
workspace = true
1818

1919
[dependencies]
20-
dashmap = { workspace = true }
2120
prost = { workspace = true }
2221
rand = { workspace = true }
2322
vortex-array = { workspace = true }

encodings/turboquant/src/centroids.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
1212
use std::sync::LazyLock;
1313

14-
use dashmap::DashMap;
1514
use vortex_error::VortexResult;
1615
use vortex_error::vortex_bail;
16+
use vortex_utils::aliases::dash_map::DashMap;
1717

1818
/// Number of numerical integration points for computing conditional expectations.
1919
const INTEGRATION_POINTS: usize = 1000;
@@ -25,7 +25,7 @@ const CONVERGENCE_EPSILON: f64 = 1e-12;
2525
const MAX_ITERATIONS: usize = 200;
2626

2727
/// Global centroid cache keyed by (dimension, bit_width).
28-
static CENTROID_CACHE: LazyLock<DashMap<(u32, u8), Vec<f32>>> = LazyLock::new(DashMap::new);
28+
static CENTROID_CACHE: LazyLock<DashMap<(u32, u8), Vec<f32>>> = LazyLock::new(DashMap::default);
2929

3030
/// Get or compute cached centroids for the given dimension and bit width.
3131
///

encodings/turboquant/src/compress.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,15 @@ pub fn turboquant_encode_mse(
109109
let norm = l2_norm(x);
110110
norms_buf.push(norm);
111111

112-
padded.fill(0.0);
112+
// Normalize and write into [..dim]; tail [dim..padded_dim] stays zero
113+
// from initialization and is never overwritten.
113114
if norm > 0.0 {
114115
let inv_norm = 1.0 / norm;
115116
for (dst, &src) in padded[..dim].iter_mut().zip(x.iter()) {
116117
*dst = src * inv_norm;
117118
}
119+
} else {
120+
padded[..dim].fill(0.0);
118121
}
119122
rotation.rotate(&padded, &mut rotated);
120123

@@ -225,12 +228,13 @@ pub fn turboquant_encode_qjl(
225228
let norm = l2_norm(x);
226229

227230
// Reproduce the same quantization as MSE encoding.
228-
padded.fill(0.0);
229231
if norm > 0.0 {
230232
let inv_norm = 1.0 / norm;
231233
for (dst, &src) in padded[..dim].iter_mut().zip(x.iter()) {
232234
*dst = src * inv_norm;
233235
}
236+
} else {
237+
padded[..dim].fill(0.0);
234238
}
235239
rotation.rotate(&padded, &mut rotated);
236240

encodings/turboquant/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ mod tests {
132132
use vortex_session::VortexSession;
133133

134134
use crate::TurboQuantConfig;
135+
use crate::rotation::RotationMatrix;
135136
use crate::turboquant_encode_mse;
136137
use crate::turboquant_encode_qjl;
137138

@@ -536,8 +537,6 @@ mod tests {
536537
/// produce identical output.
537538
#[test]
538539
fn stored_rotation_signs_produce_correct_decode() -> VortexResult<()> {
539-
use crate::rotation::RotationMatrix;
540-
541540
let fsl = make_fsl(20, 128, 42);
542541
let config = TurboQuantConfig {
543542
bit_width: 3,

encodings/turboquant/src/rotation.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,6 @@ impl RotationMatrix {
207207
}
208208
}
209209

210-
/// Apply the inverse SRHT using sign bits stored in a raw byte slice.
211-
///
212-
/// This is the hot-path function for decompression. The `signs_bytes` buffer
213-
/// contains `3 * padded_dim` bits in inverse-application order `[D₃ | D₂ | D₁]`.
214-
/// Convention: bit set (1) = +1, bit unset (0) = -1 (negate).
215-
///
216210
/// Generate a vector of random ±1 signs.
217211
fn gen_random_signs(rng: &mut StdRng, len: usize) -> Vec<f32> {
218212
(0..len)

0 commit comments

Comments
 (0)