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

perf: isSmartAccountActive param cache #8189

Merged
merged 7 commits into from
May 2, 2024

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented May 1, 2024

Closes: #XXX

What is the purpose of the change

Inspired by #8148

This param retrieval currently gets called 6 times for each tx. This requires unmarshalling all the params from the module, which is very wasteful.

Testing and Verifying

All currently existing tests that test the circuit breaker should behave the same. I will also be setting breakpoints in my QA for v25 on this feature to ensure the behavior is as expected.

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

@czarcas7ic czarcas7ic added V:state/compatible/backport State machine compatible PR, should be backported A:backport/v25.x backport patches to v25.x branch labels May 1, 2024
@czarcas7ic czarcas7ic marked this pull request as ready for review May 1, 2024 19:59
Copy link
Contributor

coderabbitai bot commented May 1, 2024

Warning

Rate Limit Exceeded

@czarcas7ic has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 50 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 836cc18 and 12f205a.

Walkthrough

The recent updates focus on optimizing the handling of the isSmartAccountActive parameter across various components. This includes direct checks for smart account activity in the circuit breaker logic and caching this parameter within the Keeper structure for improved performance. These changes streamline the process and potentially enhance the system's efficiency by reducing redundant data retrieval.

Changes

File Path Change Summary
.../circuit_breaker.go Direct check of smart account activity replacing parameter retrieval in circuit breaker logic.
.../keeper/keeper.go, .../params.go Added caching for isSmartAccountActive and a new retrieval function in the Keeper structure.

🐰✨
A hop, a skip, a code deploy,
Smart accounts now smarter, oh boy!
Cache in place, with byte and bool,
Faster checks, that’s the new rule!
🚀🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Out of diff range and nitpick comments (9)
CHANGELOG.md (9)

Line range hint 1015-1015: Ensure heading levels increment by one level at a time.


Line range hint 1027-1027: Ensure heading levels increment by one level at a time.


Line range hint 1036-1036: Ensure heading levels increment by one level at a time.


Line range hint 1041-1041: Ensure heading levels increment by one level at a time.


Line range hint 1093-1093: Ensure heading levels increment by one level at a time.


Line range hint 354-354: Remove trailing punctuation in heading.

-## v6.4.0.
+## v6.4.0

Line range hint 617-617: Avoid using bare URLs. Provide descriptive text for hyperlinks.

-https://github.com/osmosis-labs/osmosis/releases/tag/v6.4.0
+[v6.4.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.4.0)

Line range hint 675-675: Avoid using bare URLs. Provide descriptive text for hyperlinks.

-https://github.com/osmosis-labs/osmosis/releases/tag/v6.3.1
+[v6.3.1](https://github.com/osmosis-labs/osmosis/releases/tag/v6.3.1)

Line range hint 1256-1256: Ensure there are no empty links in the document.

-[]()
+[Link description](#)

Comment on lines 26 to 36
func (k Keeper) GetIsSmartAccountActive(ctx sdk.Context) bool {
isSmartAccountActiveBz := k.paramSpace.GetRaw(ctx, types.KeyIsSmartAccountActive)
if !bytes.Equal(isSmartAccountActiveBz, k.isSmartAccountActiveBz) {
var isSmartAccountActiveValue bool
err := json.Unmarshal(isSmartAccountActiveBz, &isSmartAccountActiveValue)
if err != nil {
isSmartAccountActiveValue = false
}
k.isSmartAccountActiveVal = isSmartAccountActiveValue
}
return k.isSmartAccountActiveVal
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding error logging in GetIsSmartAccountActive.

+			k.Logger(ctx).Error("failed to unmarshal isSmartAccountActive", "error", err)

This would help in debugging issues related to parameter unmarshalling failures.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (k Keeper) GetIsSmartAccountActive(ctx sdk.Context) bool {
isSmartAccountActiveBz := k.paramSpace.GetRaw(ctx, types.KeyIsSmartAccountActive)
if !bytes.Equal(isSmartAccountActiveBz, k.isSmartAccountActiveBz) {
var isSmartAccountActiveValue bool
err := json.Unmarshal(isSmartAccountActiveBz, &isSmartAccountActiveValue)
if err != nil {
isSmartAccountActiveValue = false
}
k.isSmartAccountActiveVal = isSmartAccountActiveValue
}
return k.isSmartAccountActiveVal
func (k Keeper) GetIsSmartAccountActive(ctx sdk.Context) bool {
isSmartAccountActiveBz := k.paramSpace.GetRaw(ctx, types.KeyIsSmartAccountActive)
if !bytes.Equal(isSmartAccountActiveBz, k.isSmartAccountActiveBz) {
var isSmartAccountActiveValue bool
err := json.Unmarshal(isSmartAccountActiveBz, &isSmartAccountActiveValue)
if err != nil {
k.Logger(ctx).Error("failed to unmarshal isSmartAccountActive", "error", err)
isSmartAccountActiveValue = false
}
k.isSmartAccountActiveVal = isSmartAccountActiveValue
}
return k.isSmartAccountActiveVal

@czarcas7ic
Copy link
Member Author

Blocked on #8148 (comment)

@czarcas7ic czarcas7ic marked this pull request as draft May 1, 2024 20:16
@czarcas7ic czarcas7ic marked this pull request as ready for review May 2, 2024 05:01
@nicolaslara
Copy link
Contributor

This looks good. To make this easier in the future, I think we should have a global app.BlockCache and app.AppCache (caching for the duration of the block and caching for as long as the app runs) that we pass to keepers so it's easy to reuse.

Copy link
Collaborator

@PaddyMc PaddyMc left a comment

Choose a reason for hiding this comment

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

Nice, good catch

@czarcas7ic czarcas7ic merged commit d1076da into main May 2, 2024
1 check passed
@czarcas7ic czarcas7ic deleted the adam/cache-is-smart-account-active branch May 2, 2024 18:49
mergify bot pushed a commit that referenced this pull request May 2, 2024
* isSmartAccountActive param cache

* changelog

* lint

* add comment

* logger

* assign bz

* use pointer

(cherry picked from commit d1076da)
czarcas7ic added a commit that referenced this pull request May 2, 2024
* isSmartAccountActive param cache

* changelog

* lint

* add comment

* logger

* assign bz

* use pointer

(cherry picked from commit d1076da)

Co-authored-by: Adam Tucker <[email protected]>
@github-actions github-actions bot mentioned this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v25.x backport patches to v25.x branch V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants