StableLib / stablelib

A stable library of useful TypeScript/JavaScript code
https://www.stablelib.com
Other
173 stars 35 forks source link

Avoid block copy operations in scrypt's SMix step to improve performance #4

Closed palant closed 7 years ago

palant commented 7 years ago

Function smix() in the scrypt implementation currently does something like that:

If you look closely, the copy operations are unnecessary. Instead, one can do the following:

Only the very last mix operation is slightly problematic because there is no space in V for the result any more and it needs to go into X. This issue can be avoided by allocating X and Y at the end of the V array. That's what I have done now, improves performance by around 10% for me (in both Firefox and Chrome).

dchest commented 7 years ago

Thanks, I'll take a deeper look a bit later.

palant commented 7 years ago

Any progress on that?

dchest commented 7 years ago

Sorry, didn't have time yet, but will definitely do this this week.

dchest commented 7 years ago

Thank you! Merged and published.