refactor!: instantiate client.TxConfig once for simulations#15875
Merged
Conversation
There were many instances of client.TxConfig created during operation creation for simulations, but since that value is stateless and expensive to create, we can make it once at the beginning of the simulation and pass it where needed. Prior to this optimization, by patching sim_test.go to use a fixed seed and to print out some GC details, and running this command in order to match the make target: go test -mod=readonly -run TestAppStateDeterminism -Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -timeout 24h -count=1 On my workstation (a 10-core M1 Max): there were 661,278,897,592 allocated bytes; GC ran 3,045 times constituting 3.9% of used CPU time; and the test completed in 10m2s. After applying these optimizations and that same patch, and running the same command: there were 123,353,530,520 allocated bytes (about 18.6% of the previous run); GC ran 492 times (about 16.2% of the previous run) constituting about 1.8% of used CPU time; and the test completed in 3m45s (about 37.3% of the previous run).
Contributor
Author
|
Oops, there are some tests to fix here. |
I didn't place them correctly after expanding a function signature across multiple lines.
julienrbrt
reviewed
Apr 18, 2023
|
|
||
| // WeightedOperations returns the all the slashing module operations with their respective weights. | ||
| func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { | ||
| // TODO(mr): this should be injected to NewAppModule, |
Contributor
There was a problem hiding this comment.
Is this todo getting done in this PR btw? Or is it tracked somewhere else?
This is intended to eliminate another call to create a new interface registry, when we can use the root instance of it instead.
Missing parameter added in previous commit.
julienrbrt
reviewed
Apr 19, 2023
|
|
||
| // NewAppModule creates a new AppModule object | ||
| func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, ss exported.Subspace) AppModule { | ||
| func NewAppModule( |
Contributor
There was a problem hiding this comment.
This warrants an API breaking changelog.
mark-rushakoff
added a commit
that referenced
this pull request
Apr 19, 2023
It used to be set to 5 tries, but that was taking over an hour. After some improvements (particularly #15875 and #15862), it's running much faster due to reduced allocations. Since the nondeterminism tests are no longer the bottleneck, increase the tries per seed by 1 so that it is still no longer the bottleneck, but so that we also get more confidence that results are deterministic.
8 tasks
larry0x
pushed a commit
to larry0x/cosmos-sdk
that referenced
this pull request
May 22, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
There were many instances of client.TxConfig created during operation creation for simulations, but since that value is stateless and expensive to create, we can make it once at the beginning of the simulation and pass it where needed.
Prior to this optimization, by patching sim_test.go to use a fixed seed and to print out some GC details, and running this command in order to match the make target:
On my workstation (a 10-core M1 Max): there were 661,278,897,592 allocated bytes; GC ran 3,045 times constituting 3.9% of used CPU time; and the test completed in 10m2s.
After applying these optimizations and that same patch, and running the same command: there were 123,353,530,520 allocated bytes (about 18.6% of the previous run); GC ran 492 times (about 16.2% of the previous run) constituting about 1.8% of used CPU time; and the test completed in 3m45s (about 37.3% of the previous run).
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!to the type prefix if API or client breaking changeCHANGELOG.mdReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!in the type prefix if API or client breaking change