Only load Kzg in tests if necessary and only load it once #5555
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue Addressed
Loading trusted setup file and instantiating the
Kzg
instance is very expensive (>80% of test time for most tests), and we're doing this quite a lot of times in tests even when we don't need them (e.g. pre-deneb tests), and in some cases they're loaded twice whenmock_execution_layer
is used.This PR improves this by loading
Kzg
trusted setup only once at most, if necessary.Some numbers when I run beacon chain tests locally:
unstable
branch 180s (~17m on CI)unstable
+ fix (current branch): 173sdas
branch: 990s (>55m on CI)das
branch with this fix: 269sThe difference isn't significant on
unstable
, so it looks likeKzg
initialisation time has increased quite significantly due the changes in thedas
version - there's probably more optimisation that can be done onc-kzg
but we should probably avoid loading it multiple times in a single test anyway, as we run each of these beacon chain tests once per fork.Test command used:
env FORK_NAME=deneb cargo nextest run --release --features "fork_from_env,slasher/lmdb,portable" -p beacon_chain