We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9fa3cbd commit 57a2f7bCopy full SHA for 57a2f7b
1 file changed
backend/src/embedding/index.ts
@@ -158,14 +158,9 @@ const hash = (v: string) => {
158
const addFeat = (vec: Float32Array, dim: number, key: string, w: number) => {
159
const h = hash(key);
160
const value = w * (1 - ((h & 1) << 1));
161
-
162
- // The core optimization: Check if dim is a power of two.
163
- // This check is extremely fast and allows V8's JIT to optimize heavily.
164
if ((dim > 0) && (dim & (dim - 1)) === 0) {
165
- // FAST PATH: dim is a power of two. Use bitwise AND.
166
vec[h & (dim - 1)] += value;
167
} else {
168
- // SLOW PATH: Use modulo.
169
vec[h % dim] += value;
170
}
171
0 commit comments