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

Reduce sprintf overhead in code showing up during sync profiles #7182

Merged
merged 2 commits into from
Dec 24, 2023

Conversation

ValarDragon
Copy link
Member

Reduce some sprintf overheads

This is a pretty micro-optimization. It likely has more impact for txs than epoch. In epoch it shaves like 100ms (there are way better things to shave time on there)

@ValarDragon ValarDragon added V:state/compatible/backport State machine compatible PR, should be backported A:no-changelog A:backport/v21.x backport patches to v21.x branch labels Dec 22, 2023
@github-actions github-actions bot added C:x/twap Changes to the twap module C:x/poolmanager labels Dec 22, 2023
@@ -43,7 +44,16 @@ var (

// ModuleRouteToBytes serializes moduleRoute to bytes.
func FormatModuleRouteKey(poolId uint64) []byte {
return []byte(fmt.Sprintf("%s%d", SwapModuleRouterPrefix, poolId))
// Estimate the length of the string representation of poolId
// 7 is a safe upper bound, (9999999) pools, and is an 8 byte allocation (not bad)
Copy link
Contributor

Choose a reason for hiding this comment

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

just for extra safety... should we check that poolId < 9999999?

Copy link
Member Author

Choose a reason for hiding this comment

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

All we could really do is panic, which is what will already happen here anyway

Copy link
Member Author

Choose a reason for hiding this comment

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

We can add that check to CreatePool

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok just raised the upperbound to 99,999,999,999. At $1 to create a pool, this is a third the market cap of ETH, so going to go ahead and merge!

@ValarDragon
Copy link
Member Author

Added check for it in #7203

@ValarDragon ValarDragon merged commit cb9cb4e into main Dec 24, 2023
1 check passed
@ValarDragon ValarDragon deleted the dev/reduce_sprintf_overhead branch December 24, 2023 16:09
mergify bot pushed a commit that referenced this pull request Dec 24, 2023
* Reduce sprintf overhead in code showing up during sync profiles

* Raise upperbound to not worry about it

(cherry picked from commit cb9cb4e)
ValarDragon added a commit that referenced this pull request Dec 24, 2023
… (#7204)

* Reduce sprintf overhead in code showing up during sync profiles

* Raise upperbound to not worry about it

(cherry picked from commit cb9cb4e)

Co-authored-by: Dev Ojha <[email protected]>
ValarDragon added a commit that referenced this pull request Dec 24, 2023
… (#7204)

* Reduce sprintf overhead in code showing up during sync profiles

* Raise upperbound to not worry about it

(cherry picked from commit cb9cb4e)

Co-authored-by: Dev Ojha <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v21.x backport patches to v21.x branch A:no-changelog C:x/poolmanager C:x/twap Changes to the twap module V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants