ethereum / eth-hash

The Ethereum hashing function, keccak256, sometimes (erroneously) called sha256 or sha3
MIT License
104 stars 64 forks source link

PreImage.digest()'s performance degradates significantly #10

Closed gsalgado closed 6 years ago

gsalgado commented 6 years ago

PreImage.digest() takes significantly longer after every .update() call, whereas the time for the same operation on a raw pysha3.keccak_256 instance remains constant. Here's a hackish test comparing both

gsalgado commented 6 years ago

I'm pretty sure this is because PreImage is implemented using a list to keep track of all values passed to .update() and then joins those values in a bytes object and passes it to the underlying hasher function in its .digest() method. If its .update() method just passed the value to the backend, I imagine the performance would be comparable

pipermerriam commented 6 years ago

Yeah, the current implementation was hacky at best. I think that this functionality just needs to be moved down into the backend like you said rather than caching these values locally like is currently being done.