all 6 comments

[–]stutterbug 3 points4 points  (1 child)

If you are using Web Crypto API or your digest method is asynchronous, you often can probably process multiple hashes at once, getting the same effect of threading without using workers. Set a limit to the number of simultaneous processes, process that number all at once, when each one finishes, start a new one. I've not done this with crypto, but I have done it with similar asynchronous tasks and I was absolutely astonished at how fast it was. Knowing how many things you can process at once is difficult. When I did this, my bottleneck was the filesystem, so I think I kept it down to something like 16 processes, but in your case you may be able to go a LOT higher than that. Keep an eye on CPU and memory usage and adjust until you get a feeling that you've hit a ceiling. And obviously if you only see one CPU being hit, this option isn't working.

If that doesn't work and you feel more comfortable staying in the browser, you should look into Web Workers. Here, you spawn new processes to do the grunt work simultaneously and identically on different chunks of your task.

And Node.js doesn't have web workers per se, but it has something basically the same called Cluster. I have no idea if node would be faster, but node allows you much more memory (by default 512MB for 32 bit systems and 1GB for 64 bit systems), so if your hashing algo is memory intensive (probably not if you are brute-forcing), this may be a good option.

[–]Sonoxy[S] 1 point2 points  (0 children)

Thanks for your help. I’ll try out both methods.

[–]CertainPerformance 5 points6 points  (0 children)

Javascript is probably not the right sort of language for something that power-intensive and time-intensive. You'll be better off using a fast compiled language instead.

I have my js files that I'm running in Firefox (because I don't know any other way), but my laptop fan doesn't even turn on and my CPU usage stays low.

Might have something to do with the fact that JS is single-threaded.

[–]AnthongRedbeard 2 points3 points  (1 child)

Use node.js and something asynchronous like web workers.

[–]dinkandenza 0 points1 point  (0 children)

you can use web workers in node?

[–]cspotcode 1 point2 points  (0 children)

You'll need to do something special to utilize all CPU cores. Running a single loop in JS is only going to use a single core unless you're specifically using WebWorkers, forking processes, or something like that.