Skip to content

Commit 422f265

Browse files
author
Adam B
committed
Huge speedup by using typed arrays (Int32Array) for P and S. I suspect this is because it packs the data tighter in RAM so it can fit in the CPU cache more easily.
1 parent 2ab0521 commit 422f265

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/bcrypt/impl.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,18 @@ function _crypt(b, salt, rounds, callback, progressCallback) {
407407
throw err;
408408
}
409409
rounds = (1 << rounds) >>> 0;
410-
var P = P_ORIG.slice(),
411-
S = S_ORIG.slice(),
412-
i = 0, j;
410+
411+
var P, S, i = 0, j;
412+
413+
//Use typed arrays when available - huge speedup!
414+
if (Int32Array) {
415+
P = new Int32Array(P_ORIG);
416+
S = new Int32Array(S_ORIG);
417+
} else {
418+
P = P_ORIG.slice();
419+
S = S_ORIG.slice();
420+
}
421+
413422
_ekskey(salt, b, P, S);
414423

415424
/**

0 commit comments

Comments
 (0)