perf: reuse WebRTC certificates between connections
Generating certificates takes a while, and by default (at least in browsers) they're generated for each new RTCPeerConnection
. In Firefox generating 1000 certificates takes 4 seconds (4ms per certificate) and 100% of one CPU core for me.
(async () => {
const promises = [];
for (let i = 0; i < 1000; i++) {
arr.push(RTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-256" }))
}
await Promise.all(promises);
console.log('done');
})()
I don't think this affects bootstrapping performance much as in a good implementation they're generated in parallel. It's only a matter of not hogging device's resources.
Applies to the web extension as well. Not sure how it affects privacy and security, but I don't think it should be a problem at least for proxies.
Edited by WofWca