-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
refactor!: instantiate client.TxConfig once for simulations #15875
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).
Oops, there are some tests to fix here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find!!
I didn't place them correctly after expanding a function signature across multiple lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
x/slashing/module.go
Outdated
@@ -197,8 +197,12 @@ func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { | |||
|
|||
// 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -106,7 +108,15 @@ type AppModule struct { | |||
} | |||
|
|||
// 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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warrants an API breaking changelog.
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.
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.md
Reviewers 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