typage
typage copied to clipboard
15× slowdown in Chrome when DevTools is open
I ran the following code in the major browsers, node, and bun:
const { Encrypter, Decrypter, generateIdentity, identityToRecipient } =
await age();
// Encrypt and decrypt a file with a new recipient / identity pair.
const start = performance.now();
const e = new Encrypter();
e.setPassphrase(
"burst-swarm-slender-curve-ability-various-crystal-moon-affair-three",
);
const ciphertext = e.encrypt("Hello, age!");
const d = new Decrypter();
d.addPassphrase(
"burst-swarm-slender-curve-ability-various-crystal-moon-affair-three",
);
const out = d.decrypt(ciphertext, "text");
console.log(out);
console.log(performance.now() - start);
(This is just the passphrase example from the README with two lines added to measure duration.)
All on macOS 14.0 using M1 Max:
- Chrome 119: ≈14000ms
- Safari: ≈1000ms
- Firefox: ≈1000ms
node: ≈1000msbun: ≈1000ms
This is "only" 4 orders of magnitude in terms of the work factor, but I'd love to figure out what's going on in Chrome.
Repro with splits for each of the 4 operations: https://garron.net/temp/age-perf
I just figured something out moments ago: the performance slowdown in Chrome happens only when I have DevTools open. When DevTools is closed, the results are nearly in line with other browsers.
Apparently this is a known WontFix issue? 😢
https://bugs.chromium.org/p/chromium/issues/detail?id=1322417
15× is rather extreme, and the only reason I was able to find that bug is because of my experience looking up bugs as a Chrome developer. I understand that most devs would expect DevTools functionality over maximum performance, but this seems like it would still be a nasty surprise/source of confusion for anyone using the library without being aware of the caveat.
(SEE EDIT) In fact, this makes age.ts kind of unusable for my current library, because anyone developing with it in Chrome will be hit by extreme performance issues. Even by lowering the scrypt work factor to 2, it doesn't seem to get much better. 😬
(EDIT: looks like I was testing a bit wrong, a work factor of 12 turns out to be okay.)
According to https://bugs.chromium.org/p/chromium/issues/detail?id=1322417 the main culprit seems to be WASM.
Having a pure JS implementation (as suggested in #20) might mitigate this.
I think this is now mitigated by switching to pure JS.