Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Fix quadratic balance query#573

Merged
codchen merged 2 commits intomainfrom
tony/fix-quadratic-balance-query
Apr 1, 2025
Merged

Fix quadratic balance query#573
codchen merged 2 commits intomainfrom
tony/fix-quadratic-balance-query

Conversation

@codchen
Copy link
Copy Markdown
Collaborator

@codchen codchen commented Mar 31, 2025

Describe your changes and provide context

Previously GetAllBalances would perform slice copy operation for each iterator Next call due to how Coin::Add is implemented. The reason for the copy is because Coin:Add needs to sort the resulting slice. However this is unnecessary because at the end of GetAllBalances the slice would sorted again anyway. This PR changes the iterator operation to be a simple append, so that the total time complexity would be O(n) instead of O(n^2)

Testing performed to validate your change

unit test

@codchen codchen requested a review from philipsu522 March 31, 2025 04:22
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.57%. Comparing base (8a2b961) to head (d302345).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #573      +/-   ##
==========================================
- Coverage   54.57%   54.57%   -0.01%     
==========================================
  Files         632      632              
  Lines       55267    55272       +5     
==========================================
- Hits        30164    30162       -2     
- Misses      22946    22951       +5     
- Partials     2157     2159       +2     
Files with missing lines Coverage Δ
x/bank/keeper/view.go 84.72% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codchen codchen merged commit 3d77518 into main Apr 1, 2025
15 checks passed
@codchen codchen deleted the tony/fix-quadratic-balance-query branch April 1, 2025 04:24
codchen added a commit that referenced this pull request Apr 26, 2025
## Describe your changes and provide context
Previously `GetAllBalances` would perform slice copy operation for each
iterator `Next` call due to how `Coin::Add` is implemented. The reason
for the copy is because `Coin:Add` needs to sort the resulting slice.
However this is unnecessary because at the end of `GetAllBalances` the
slice would sorted again anyway. This PR changes the iterator operation
to be a simple append, so that the total time complexity would be O(n)
instead of O(n^2)

## Testing performed to validate your change
unit test
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants