FriendlyCaptcha / friendly-pow

The PoW challenge library used by Friendly Captcha
201 stars 20 forks source link

Bunch of improvments #2

Closed MaxGraey closed 4 years ago

MaxGraey commented 4 years ago
gzuidhof commented 4 years ago

Wow, thank you so much! This is really amazing.

I didn't expect there to be so much improvement in speed left without making it unreadable, but you've done a really good job. I am super impressed because the code you optimized wasn't the most clear anymore after I iterated on it a lot for speed (sorry about that!).

My poor man's benchmark has been to edit the expectation here and make it really high (e.g. 10 million). And then run:

npm run test:as -- --file solver.astest.ts

This runs in Node, I've found that it's up to in Chrome or Firefox it can be another 50% faster (my node version is 12.13.1).

Benchmarks

Without your changes (3 runs):

[Actual]: 2242152.466367713
[Actual]: 2309468.8221709006
[Actual]: 2227171.4922049

With your changes (3 runs)

[Actual]: 4032258.064516129
[Actual]: 4016064.2570281127
[Actual]: 3952569.169960474

We went from 2.25 million hashes to 4 million hashes per second, really impressive! I didn't expect this to be possible without SIMD. The build size went from 3.44KB to 3.24KB, so even there it's a small improvement 🚀.

MaxGraey commented 4 years ago

What do you think btw made external assemblyscript module for blake2b64 (as-blake2b)? Similar to as-sha256

gzuidhof commented 4 years ago

Yeah I'd be happy to make it an external module, but we do need to verify that the implementation is actually correct.

All my tests and use cases are passing in a single message that is under 128 bytes, who knows whether it is also correct for longer messages, and messages that are streamed.

gzuidhof commented 4 years ago

Feel free to merge when you are ready! thanks again

MaxGraey commented 4 years ago

All my tests and use cases are passing in a single message that is under 128 bytes

Oh, definitely need more tests)

Feel free to merge when you are ready

It's ready