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

refactor!: instantiate client.TxConfig once for simulations #15875

Merged
merged 9 commits into from
Apr 19, 2023

Conversation

mark-rushakoff
Copy link
Member

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:

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).


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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

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).
@mark-rushakoff
Copy link
Member Author

Oops, there are some tests to fix here.

Copy link
Member

@tac0turtle tac0turtle left a 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.
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@@ -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,
Copy link
Member

@julienrbrt julienrbrt Apr 18, 2023

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(
Copy link
Member

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.

@julienrbrt julienrbrt changed the title refactor: instantiate client.TxConfig once for simulations refactor!: instantiate client.TxConfig once for simulations Apr 19, 2023
@mark-rushakoff mark-rushakoff added this pull request to the merge queue Apr 19, 2023
Merged via the queue into main with commit 7b10ada Apr 19, 2023
@mark-rushakoff mark-rushakoff deleted the mr/simtest-minimize-txconfig-calls branch April 19, 2023 12:49
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.
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants