Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_bytes() adds significant overhead to keccak() #95

Open
gsalgado opened this issue Apr 30, 2018 · 5 comments
Open

to_bytes() adds significant overhead to keccak() #95

gsalgado opened this issue Apr 30, 2018 · 5 comments

Comments

@gsalgado
Copy link
Contributor

That function seems to add a big overhead to keccak(), and given its performance-critical nature I think we should consider dropping it (making keccak() accept only bytes). Here are some numbers showing the overhead it adds when compared to running the backend implementation directly:

$ python -m timeit -n 100000 -v -s "import os; from eth_hash.utils import auto_choose_backend; backend = auto_choose_backend()" "backend.keccak256(os.urandom(32))"
raw times: 1.81 1.82 1.85
100000 loops, best of 3: 18.1 usec per loop
$ python -m timeit -n 100000 -v -s "import os; from eth_utils import keccak" "keccak(os.urandom(32))"
raw times: 2.51 2.45 2.44
100000 loops, best of 3: 24.4 usec per loop
@pipermerriam
Copy link
Member

pipermerriam commented Apr 30, 2018

@gsalgado I believe our intent with eth-hash was to provide a fast low level API that accepts only bytes, and for eth_utils.keccak to be the slightly higher level API. Performance focused code should directly use eth-hash, otherwise eth_utils provides a slightly friendlier API.

However, I can get onboard with dropping support for text/hexstr since I'd bet we have very few call sites which use non-bytes inputs for keccak.

@gsalgado gsalgado mentioned this issue Apr 30, 2018
gsalgado added a commit to gsalgado/eth-utils that referenced this issue Apr 30, 2018
It just added support for text/hex to eth_hash's version, but that has a
significant performance impact and was not really used anywhere, so
deprecating it now so that it can be removed in a future version.

Closes: ethereum#95
@carver
Copy link
Collaborator

carver commented Apr 30, 2018

I get why trinity would want to use eth-hash's keccak, but I don't understand the desire to remove the convenience one from eth-utils.

@gsalgado
Copy link
Contributor Author

gsalgado commented May 2, 2018

Mainly because doing it implicitly on every call adds significant overhead to a performance-critical piece of code, but I'd also argue that there's no point in having a keccak func in two different eth- packages

@pipermerriam
Copy link
Member

I think I'm now 👎 on removing keccak from eth-utils. They may be a minority use case, but having a keccak available which can take encoded hex and utf8 strings is useful and use cases which require performance can directly use eth-hash.

@carver
Copy link
Collaborator

carver commented May 2, 2018

Maybe it would help to add a note about performance in the eth-utils docs, and link to eth-hash's keccak?

Uxio0 added a commit to safe-global/safe-eth-py that referenced this issue Jun 15, 2022
While developing Safe Tx Service we found out that a lot of time was spent
on converting addresses from `bytes` to `ChecksumAddress`. Biggest part
of this time was overhead added on `eth_utils` library to `keccak256`
function.

So we decided to use `pysha3` library (way faster than `pycryptodome`)
directly. That's why we implemented new methods:

- fast_keccak
- fast_keccak_hex
- fast_keccak_hex
- fast_to_checksum_address
- fast_bytes_to_checksum_address
- fast_is_checksum_address

This is also very relevant for the `EthereumAddressV2Field`, as it
stores addresses as `bytes` on database and returns them as
`ChecksumAddress`

Related to:
  - ethereum/eth-utils#95
  - ethereum/eth-hash#35
Uxio0 added a commit to safe-global/safe-eth-py that referenced this issue Jun 15, 2022
While developing Safe Tx Service we found out that a lot of time was spent
on converting addresses from `bytes` to `ChecksumAddress`. Biggest part
of this time was overhead added on `eth_utils` library to `keccak256`
function.

So we decided to use `pysha3` library (way faster than `pycryptodome`)
directly. That's why we implemented new methods:

- fast_keccak
- fast_keccak_hex
- fast_keccak_hex
- fast_to_checksum_address
- fast_bytes_to_checksum_address
- fast_is_checksum_address

This is also very relevant for the `EthereumAddressV2Field`, as it
stores addresses as `bytes` on database and returns them as
`ChecksumAddress`

Related to:
  - ethereum/eth-utils#95
  - ethereum/eth-hash#35
Uxio0 added a commit to safe-global/safe-eth-py that referenced this issue Jun 16, 2022
While developing Safe Tx Service we found out that a lot of time was spent
on converting addresses from `bytes` to `ChecksumAddress`. Biggest part
of this time was overhead added on `eth_utils` library to `keccak256`
function.

So we decided to use `pysha3` library (way faster than `pycryptodome`)
directly. That's why we implemented new methods:

- fast_keccak
- fast_keccak_hex
- fast_keccak_hex
- fast_to_checksum_address
- fast_bytes_to_checksum_address
- fast_is_checksum_address

This is also very relevant for the `EthereumAddressV2Field`, as it
stores addresses as `bytes` on database and returns them as
`ChecksumAddress`

Related to:
  - ethereum/eth-utils#95
  - ethereum/eth-hash#35
Uxio0 added a commit to safe-global/safe-eth-py that referenced this issue Jun 16, 2022
While developing Safe Tx Service we found out that a lot of time was spent
on converting addresses from `bytes` to `ChecksumAddress`. Biggest part
of this time was overhead added on `eth_utils` library to `keccak256`
function.

So we decided to use `pysha3` library (way faster than `pycryptodome`)
directly. That's why we implemented new methods:

- fast_keccak
- fast_keccak_hex
- fast_keccak_hex
- fast_to_checksum_address
- fast_bytes_to_checksum_address
- fast_is_checksum_address

This is also very relevant for the `EthereumAddressV2Field`, as it
stores addresses as `bytes` on database and returns them as
`ChecksumAddress`

Related to:
  - ethereum/eth-utils#95
  - ethereum/eth-hash#35
Uxio0 added a commit to safe-global/safe-eth-py that referenced this issue Jun 16, 2022
While developing Safe Tx Service we found out that a lot of time was spent
on converting addresses from `bytes` to `ChecksumAddress`. Biggest part
of this time was overhead added on `eth_utils` library to `keccak256`
function.

So we decided to use `pysha3` library (way faster than `pycryptodome`)
directly. That's why we implemented new methods:

- fast_keccak
- fast_keccak_hex
- fast_keccak_hex
- fast_to_checksum_address
- fast_bytes_to_checksum_address
- fast_is_checksum_address

This is also very relevant for the `EthereumAddressV2Field`, as it
stores addresses as `bytes` on database and returns them as
`ChecksumAddress`

Related to:
  - ethereum/eth-utils#95
  - ethereum/eth-hash#35
Uxio0 added a commit to safe-global/safe-eth-py that referenced this issue Jun 16, 2022
While developing Safe Tx Service we found out that a lot of time was spent
on converting addresses from `bytes` to `ChecksumAddress`. Biggest part
of this time was overhead added on `eth_utils` library to `keccak256`
function.

So we decided to use `pysha3` library (way faster than `pycryptodome`)
directly. That's why we implemented new methods:

- fast_keccak
- fast_keccak_hex
- fast_keccak_hex
- fast_to_checksum_address
- fast_bytes_to_checksum_address
- fast_is_checksum_address

This is also very relevant for the `EthereumAddressV2Field`, as it
stores addresses as `bytes` on database and returns them as
`ChecksumAddress`

Related to:
  - ethereum/eth-utils#95
  - ethereum/eth-hash#35
Uxio0 added a commit to safe-global/safe-eth-py that referenced this issue Jun 16, 2022
While developing Safe Tx Service we found out that a lot of time was spent
on converting addresses from `bytes` to `ChecksumAddress`. Biggest part
of this time was overhead added on `eth_utils` library to `keccak256`
function.

So we decided to use `pysha3` library (way faster than `pycryptodome`)
directly. That's why we implemented new methods:

- fast_keccak
- fast_keccak_hex
- fast_keccak_hex
- fast_to_checksum_address
- fast_bytes_to_checksum_address
- fast_is_checksum_address

This is also very relevant for the `EthereumAddressV2Field`, as it
stores addresses as `bytes` on database and returns them as
`ChecksumAddress`

Related to:
  - ethereum/eth-utils#95
  - ethereum/eth-hash#35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants