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

(CL): Improve GetTickLiquidityForRange and GetTickLiquidityNetInDirection query performance by using iterators #4805

Merged
merged 9 commits into from
Apr 5, 2023

Conversation

mattverse
Copy link
Member

Closes: #4704

What is the purpose of the change

Improves performance ofGetTickLiquidityForRange query by using prefix iterators directly.

Brief Changelog

Improve GetTickLiquidityForRange query performance by using iterators

Testing and Verifying

Existing tests passes

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? (yes / no)
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (yes / no)
  • How is the feature or change documented? (not applicable / specification (x/<module>/spec/) / Osmosis docs repo / not documented)

@mattverse mattverse added V:state/compatible/no_backport State machine compatible PR, depends on prior breaks C:x/concentrated-liquidity F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board and removed C:x/concentrated-liquidity labels Mar 31, 2023
Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

Nice work.

Have a couple of questions/comments:

  • Can We rename the function to the GetTickLiquidityForFullRange because we do not allow specifying lower and upper bounds?
  • The godoc needs to be updated
  • Can this iterator improvement algorithm be also applied to the query introduce in: (CL): Add Liquidity Net In Direction Query #4714

tick, err := k.getTickByTickIndex(ctx, poolId, nextTick)
keyTick := types.KeyTick(poolId, tickIndex)
tickStruct := model.TickInfo{}
found, err := osmoutils.Get(store, keyTick, &tickStruct)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have to re-get the value? Can't we just get it from iterator.Value()

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed it to use directly using iterator.Value()

x/concentrated-liquidity/tick.go Outdated Show resolved Hide resolved
@mattverse
Copy link
Member Author

Hey @p0mvn thanks for the review, while I was resolving your suggestions, I actually came across the fundamental question of needing to improve query performance via this PR.

Right now, the code operates based on NextInitialized tick. If we take a look at the implementation,
https://github.com/osmosis-labs/osmosis/blob/8ec7dadbaf/x/concentrated-liquidity/internal/swapstrategy/one_for_zero.go#L167-L192 we can see that it uses iterators any way. Thus I came to a conclusion that this PR is not necessarily needed in the first place. Wdyt?

@mattverse mattverse changed the title (CL): Improve GetTickLiquidityForRange query performance by using iterators (CL): Improve GetTickLiquidityForRange and GetTickLiquidityNetInDirection query performance by using iterators Apr 5, 2023
@mattverse
Copy link
Member Author

Hey @p0mvn thanks for the review, in the most recent commit I have made the following changes,

  • Add GetTickLiquidityNetInDirection improvement
  • Godoc updated
  • Rename GetTickLiquidityForFullRange
  • Address and resolve other comments made in previous iteration of review,
    Please take a look!

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

Awesome, LGTM!

x/concentrated-liquidity/tick.go Outdated Show resolved Hide resolved
@p0mvn p0mvn merged commit e9b5d44 into main Apr 5, 2023
@p0mvn p0mvn deleted the mattverse/improve-cl-perf branch April 5, 2023 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/concentrated-liquidity F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board V:state/compatible/no_backport State machine compatible PR, depends on prior breaks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CL] Improve Performance of Liquidity Query via using iterators
2 participants