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

Use a for loop instead of a while loop in LockupTranched #879

Closed
PaulRBerg opened this issue Apr 5, 2024 · 0 comments
Closed

Use a for loop instead of a while loop in LockupTranched #879

PaulRBerg opened this issue Apr 5, 2024 · 0 comments
Assignees
Labels
effort: low Easy or tiny task that takes less than a day. priority: 2 We will do our best to deal with this. type: perf Change that improves performance. work: clear Sense-categorize-respond. The relationship between cause and effect is clear.

Comments

@PaulRBerg
Copy link
Member

All else being equal, a for loop is better than a while loop in a blockchain context. This is due to the risk of overflowing the block's gas limit. With a for loop, this risk is completely mitigated.

It is possible to turn the following while loop into a for loop:

https://github.com/sablier-labs/v2-core/blob/76e29fee33befaeb54a82473c28cf182e6f8855d/src/SablierV2LockupTranched.sol#L200-L207

Like so:

uint128 streamedAmount = tranches[0].amount;
for (uint256 i = 1; i < tranches.length; ++i) {
    // If a tranche's timestamp is equal to the current time, it is considered vested.
    if (tranches[i].timestamp > currentTime) {
        break;
    }
    streamedAmount += tranches[i].amount;
}
@PaulRBerg PaulRBerg added priority: 2 We will do our best to deal with this. effort: low Easy or tiny task that takes less than a day. work: clear Sense-categorize-respond. The relationship between cause and effect is clear. type: perf Change that improves performance. labels Apr 5, 2024
@PaulRBerg PaulRBerg self-assigned this Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: low Easy or tiny task that takes less than a day. priority: 2 We will do our best to deal with this. type: perf Change that improves performance. work: clear Sense-categorize-respond. The relationship between cause and effect is clear.
Projects
None yet
Development

No branches or pull requests

2 participants