-
Notifications
You must be signed in to change notification settings - Fork 607
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
Make CL calculations not update accumulators #7689
Conversation
spreadRewardAccum *accum.AccumulatorObject, uptimeAccums *[]*accum.AccumulatorObject, | ||
tokenInDenom string) (SwapState, error) { | ||
tokenInDenom string, updateAccumulators bool) (SwapState, error) { |
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.
in a subsequent PR I think I'll package these accum vars into their own struct.
return swapState, err | ||
// Retrieve the liquidity held in the next closest initialized tick | ||
spreadRewardGrowth := sdk.DecCoin{Denom: tokenInDenom, Amount: swapState.globalSpreadRewardGrowthPerUnitLiquidity} | ||
_, err := k.crossTick(ctx, p.GetId(), nextInitializedTick, &nextInitializedTickInfo, spreadRewardGrowth, spreadRewardAccum.GetValue(), *uptimeAccums) |
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.
In a subsequent PR I'll refactor crossTick to not return LiquidityNet, it just reads that from one of the args.
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!
This should have a changelog |
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.
LGTM
WalkthroughThe recent updates introduce enhancements focusing on speed and gas efficiency for the Osmosis project. A notable feature prevents state writes during CL price estimations, optimizing performance. Modifications in the Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (4)
- CHANGELOG.md (1 hunks)
- x/concentrated-liquidity/export_test.go (2 hunks)
- x/concentrated-liquidity/swaps.go (14 hunks)
- x/concentrated-liquidity/swaps_test.go (4 hunks)
Check Runs (9)
osmosisd-linux-arm64 completed (1)
osmosisd-darwin-arm64 completed (1)
osmosisd-linux-amd64 completed (1)
get_diff completed (2)
Run golangci-lint completed (1)
osmosisd-darwin-amd64 completed (1)
test completed (1)
Run super-linter completed (1)
Check Actions completed (2)
Additional comments: 11
x/concentrated-liquidity/export_test.go (2)
- 73-75: The addition of the
updateAccumulators
boolean parameter to theComputeOutAmtGivenIn
function signature is aligned with the PR objectives to optimize performance by conditionally updating accumulators. This change allows for bypassing accumulator updates when not necessary, potentially reducing CPU and I/O time. Ensure that all calls to this function have been updated to include the new parameter.- 96-98: Similarly, the
ComputeInAmtGivenOut
function now accepts anupdateAccumulators
boolean parameter, enabling the same performance optimization asComputeOutAmtGivenIn
. This consistent approach across both functions is beneficial for maintaining the efficiency of the system. As with the previous function, verify that all invocations ofComputeInAmtGivenOut
have been adjusted to pass the new parameter.x/concentrated-liquidity/swaps.go (6)
- 253-253: The introduction of the
updateAccumulators
parameter incomputeOutAmtGivenIn
andcomputeInAmtGivenOut
functions is a significant change aimed at optimizing performance by conditionally updating accumulators. This aligns with the PR's objective to enhance efficiency by reducing unnecessary operations.- 338-349: Adding the
getAccumulators
parameter to theswapSetup
function is a strategic change that enables conditional retrieval of spread accumulators. This is a crucial optimization step that contributes to the overall goal of improving synchronization speed and reducing CPU and I/O time.- 441-447: The conditional update of spread reward growth within the
computeOutAmtGivenIn
function, controlled by theupdateAccumulators
flag, is a thoughtful addition. It ensures that spread reward growth is only updated when necessary, potentially reducing the computational overhead. However, it's important to ensure that this conditional logic does not inadvertently skip necessary updates in scenarios where accumulators should be updated.- 498-501: The conditional addition of spread reward growth to the pool-global spread reward accumulator in
computeOutAmtGivenIn
is another optimization that aligns with the PR's objectives. This selective updating mechanism can contribute to performance improvements by avoiding unnecessary state changes.- 576-581: Similar to the
computeOutAmtGivenIn
function, the conditional update of spread reward growth incomputeInAmtGivenOut
based on theupdateAccumulators
flag is a prudent optimization. It's essential to ensure that this conditional logic is thoroughly tested to confirm that it behaves as expected across all relevant scenarios.- 629-631: The conditional addition of spread reward growth to the pool-global spread reward accumulator in
computeInAmtGivenOut
is consistent with the PR's goal of optimizing performance. This selective approach to updating the accumulator should be beneficial, provided it's correctly implemented to cover all necessary cases.CHANGELOG.md (1)
- 63-63: The changelog entry for PR Make CL calculations not update accumulators #7689 is clear and concise, accurately summarizing the feature's purpose and impact.
x/concentrated-liquidity/swaps_test.go (2)
- 2030-2030: Please verify the correctness of the line number reference
2030~
in the comment. It seems to be placed as a placeholder or error. Ensure that the correct line number or code reference is provided to avoid confusion.- 2759-2759: Please verify the correctness of the line number reference
2759~
in the comment. It seems to be placed as a placeholder or error. Ensure that the correct line number or code reference is provided to avoid confusion.
cacheCtx, | ||
pool.GetId(), | ||
test.TokenIn, test.TokenOutDenom, | ||
test.SpreadFactor, test.PriceLimit) | ||
test.SpreadFactor, test.PriceLimit, true) | ||
|
||
if test.ExpectErr { | ||
s.Require().Error(err) |
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.
📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [203-203]
The function populateSwapTestFields
modifies the test cases in place to ensure that certain fields are not nil. Consider adding a comment to clarify the purpose of this function and why it's necessary to modify the test cases in this manner. This will improve the readability and maintainability of the test suite.
+ // populateSwapTestFields ensures that all test cases have non-nil expected values for certain fields.
Make CL CalcOutAmtGivenIn and CalcInAmtGivenOut skip fetching and setting the accumulators. This saves notably on the CPU and I/O time at hand here. This should also help smart contracts.
At our last benchmark, this should be saving .75% of sync speed, but is of much higher impact with all our v24 work conjoined. (sync speed saving all coming from protorev) This also paves the way for a second PR removing the CacheCtx on
CalcOutAmtGivenIn
which would save another 1% at current benchmarks. (Also from protorev)Summary by CodeRabbit
New Features
Refactor