-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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: Remove an extra heap allocation from NewLegacyDec #19466
Conversation
This comment has been minimized.
This comment has been minimized.
WalkthroughWalkthroughThe update focuses on optimizing specific math operations 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: 0
Configuration used: .coderabbit.yml
Files selected for processing (1)
- math/dec.go (1 hunks)
Additional comments: 1
math/dec.go (1)
- 105-107: The optimization introduced in the
LegacyNewDecWithPrec
function by using a local variablebi
to store thebig.Int
representation ofi
and then using it for multiplication withprecisionMultiplier(prec)
is a good practice for reducing unnecessary heap allocations. This change is expected to slightly improve the performance by avoiding the direct use ofbig.NewInt(i)
for multiplication, which can lead to extra heap allocations. The logic of the function remains intact, ensuring that the functionality is preserved while enhancing performance.However, it's important to ensure that this optimization does not introduce any side effects in the usage of the
LegacyNewDecWithPrec
function across the Cosmos SDK. Given the nature of the change, it's unlikely to cause functional regressions, but a thorough testing strategy should be in place to validate the change across different scenarios whereLegacyNewDecWithPrec
is used.
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: 0
Configuration used: .coderabbit.yml
Files selected for processing (1)
- math/CHANGELOG.md (1 hunks)
Additional comments: 1
math/CHANGELOG.md (1)
- 46-46: The changelog entry for PR 19466 accurately reflects the changes made to optimize the
math.NewLegacyDec
function by reducing heap allocation. It follows the project's guidelines for changelog entries, grouping it under "Features" and providing a link to the PR for more details. This entry helps users understand the impact of the changes without needing to delve into the code or PR discussion directly.
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.
Thanks! LGTM
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
Ditto #19467 (comment) |
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: 0
Configuration used: .coderabbit.yml
Files selected for processing (2)
- math/CHANGELOG.md (1 hunks)
- math/dec.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- math/CHANGELOG.md
- math/dec.go
Description
Performance improvement to NewLegacyDec. Its pretty small impact in terms of the whole system, but noticed it so figured I'd make a quick PR for it.
This is covered by existing tests.
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...
!
in the type prefix if API or client breaking changeCHANGELOG.md
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...
Summary by CodeRabbit
math
module for improved performance by updating theLegacyNewDecWithPrec
function.