crate-crypto / go-eth-kzg

Apache License 2.0
29 stars 22 forks source link

Slow eth initialization #4

Closed Inphi closed 1 year ago

Inphi commented 1 year ago

The eth package contains an init function that takes a while to run setup a crypto context. As a result all downstream users of the package end up incurring the cost of initialization even when the eth package isn't used at runtime. In particular, go-ethereum has several utilities that indirectly pull down eth and these utilities are used for test generators, retesteth and python tests. These utilities are run repeatedly and ideally should have quick startup times.

I've narrowed down the issue to be the api.parseTrustedSetup. Here's a flamegraph of a sample run. Here the init function took 300ms to run on my machine: image

Dunno how feasible it'd be to optimize parsing the trusted setup such that init runs in under 10 milliseconds. Though even deferred initialization until the user uses the crypto context would work too. Most short-lived runs in go-ethereum do not use eth.

kevaundray commented 1 year ago

Hello!

I just merged https://github.com/crate-crypto/go-proto-danksharding-crypto/pull/6 which gave me a considerable difference on the startup time.

Let me know if that helps and I'll open a PR to move it into geth

Inphi commented 1 year ago

Thanks. That did help and also removing the init function made it possible for users to initialize the crypto context only when it's needed.