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

Slight optimization in {Helpers-checkCreateWithTimestamps} for LockupLinear #878

Closed
PaulRBerg opened this issue Apr 5, 2024 · 1 comment
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

When the cliff time is zero, the following check is redundant because the cliff time can never be greater than the end time (thanks to the if checks at the beginning of the function):

https://github.com/sablier-labs/v2-core/blob/76e29fee33befaeb54a82473c28cf182e6f8855d/src/libraries/Helpers.sol#L105-L108

It just so happens that the previous if checks the value of the cliff time. Thus, there's an opportunity to perform a gas optimization like this:

// A cliff time of zero means there is no cliff, so we only perform the following checks if a cliff time is set.
if (range.cliff > 0) {
    // Check: the start time is strictly less than the cliff time.
    if (range.start >= range.cliff) {
        revert Errors.SablierV2LockupLinear_StartTimeNotLessThanCliffTime(range.start, range.cliff);
    }

    // Check: the cliff time is strictly less than the end time.
    if (range.cliff >= range.end) {
        revert Errors.SablierV2LockupLinear_CliffTimeNotLessThanEndTime(range.cliff, range.end);
    }
}

Cc @sablier-labs/solidity.

@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
@smol-ninja
Copy link
Member

Good observation.

PaulRBerg added a commit that referenced this issue Apr 5, 2024
docs: improve writing in NatSpec
test: apply "seconds" keyword
andreivladbrg added a commit that referenced this issue Apr 9, 2024
* docs: improve wording in NatSpec

chore: improve wording comments
chore: misc improvements and renames
docs: capitalize ID
refactor: improve variable names
refactor: separate max segment and tranche counts
refactor: use for loop instead of while

* build: bump OpenZeppelin to v5.0.2

* docs: improve writing in NatSpec

perf: optimize "_update" by testing "_isTransferable" last
test: apply "inheritdoc"
test: define "withdrawAmount" once
test: improve function names
test: improve writing in comments
test: set the license to "UNLICENSED"

* refactor: rename "streamingModel" to "sablierModel"

docs: improve writing in NatSpec
refactor: rename "sablierAddress" to "sablierStringified"

* refactor: rename internal create function

* chore: singular Check, Effect, Interaction

docs: improve writing in custom errors' NatSpec

* perf: close #878

docs: improve writing in NatSpec
test: apply "seconds" keyword

* refactor: reorder checks

chore: improve writing in comments
test: bring back test in "createWithDurations"
test: close #880
test: fuzz cliff time as zero
test: improve BTs and associated modifiers

* test: remove unused import

* test: include map symbol test for lockup tranched
docs: _create in NatSpec

* revert: bring back GPL V3 license in mocks

chore: fix segments reference
fix: mistaken "cliffs" array

* refactor: update precompiles

* test: reuse "createWithTimestamps" modifiers

* test: revert max counts to 500

* test: use lockup object

* style: correct bad formated natspec

* refactor: rename "currentTime" to "blockTimestamp"

docs: improve wording in comments
perf: use "unchecked" for tranche calculations
refactor: rename variables

* docs: improve writing in NatSpec

* refactor: order functions and fields alphabetically

* refactor: rename variable

* docs: capitalize IDs

chore: update "filter_paths"
docs: improve writing in comments
refactor: include "streamId" in "SablierV2Lockup_WithdrawToZeroAddress"
refactor: alphabetical order

* build: bump sphinx

* test: remove ERC721Mock and use forge mock

* test: update precompiles

* chore: say "block timestamp" in comments

* refactor: update gas snapshot

test: replace "maxUint40" with "maxOfThree"

* chore: add trailing slash

* build: bump PRBMath

---------

Co-authored-by: smol-ninja <[email protected]>
Co-authored-by: andreivladbrg <[email protected]>
andreivladbrg added a commit that referenced this issue Jul 3, 2024
* docs: improve wording in NatSpec

chore: improve wording comments
chore: misc improvements and renames
docs: capitalize ID
refactor: improve variable names
refactor: separate max segment and tranche counts
refactor: use for loop instead of while

* build: bump OpenZeppelin to v5.0.2

* docs: improve writing in NatSpec

perf: optimize "_update" by testing "_isTransferable" last
test: apply "inheritdoc"
test: define "withdrawAmount" once
test: improve function names
test: improve writing in comments
test: set the license to "UNLICENSED"

* refactor: rename "streamingModel" to "sablierModel"

docs: improve writing in NatSpec
refactor: rename "sablierAddress" to "sablierStringified"

* refactor: rename internal create function

* chore: singular Check, Effect, Interaction

docs: improve writing in custom errors' NatSpec

* perf: close #878

docs: improve writing in NatSpec
test: apply "seconds" keyword

* refactor: reorder checks

chore: improve writing in comments
test: bring back test in "createWithDurations"
test: close #880
test: fuzz cliff time as zero
test: improve BTs and associated modifiers

* test: remove unused import

* test: include map symbol test for lockup tranched
docs: _create in NatSpec

* revert: bring back GPL V3 license in mocks

chore: fix segments reference
fix: mistaken "cliffs" array

* refactor: update precompiles

* test: reuse "createWithTimestamps" modifiers

* test: revert max counts to 500

* test: use lockup object

* style: correct bad formated natspec

* refactor: rename "currentTime" to "blockTimestamp"

docs: improve wording in comments
perf: use "unchecked" for tranche calculations
refactor: rename variables

* docs: improve writing in NatSpec

* refactor: order functions and fields alphabetically

* refactor: rename variable

* docs: capitalize IDs

chore: update "filter_paths"
docs: improve writing in comments
refactor: include "streamId" in "SablierV2Lockup_WithdrawToZeroAddress"
refactor: alphabetical order

* build: bump sphinx

* test: remove ERC721Mock and use forge mock

* test: update precompiles

* chore: say "block timestamp" in comments

* refactor: update gas snapshot

test: replace "maxUint40" with "maxOfThree"

* chore: add trailing slash

* build: bump PRBMath

---------

Co-authored-by: smol-ninja <[email protected]>
Co-authored-by: andreivladbrg <[email protected]>
andreivladbrg added a commit that referenced this issue Jul 3, 2024
* docs: improve wording in NatSpec

chore: improve wording comments
chore: misc improvements and renames
docs: capitalize ID
refactor: improve variable names
refactor: separate max segment and tranche counts
refactor: use for loop instead of while

* build: bump OpenZeppelin to v5.0.2

* docs: improve writing in NatSpec

perf: optimize "_update" by testing "_isTransferable" last
test: apply "inheritdoc"
test: define "withdrawAmount" once
test: improve function names
test: improve writing in comments
test: set the license to "UNLICENSED"

* refactor: rename "streamingModel" to "sablierModel"

docs: improve writing in NatSpec
refactor: rename "sablierAddress" to "sablierStringified"

* refactor: rename internal create function

* chore: singular Check, Effect, Interaction

docs: improve writing in custom errors' NatSpec

* perf: close #878

docs: improve writing in NatSpec
test: apply "seconds" keyword

* refactor: reorder checks

chore: improve writing in comments
test: bring back test in "createWithDurations"
test: close #880
test: fuzz cliff time as zero
test: improve BTs and associated modifiers

* test: remove unused import

* test: include map symbol test for lockup tranched
docs: _create in NatSpec

* revert: bring back GPL V3 license in mocks

chore: fix segments reference
fix: mistaken "cliffs" array

* refactor: update precompiles

* test: reuse "createWithTimestamps" modifiers

* test: revert max counts to 500

* test: use lockup object

* style: correct bad formated natspec

* refactor: rename "currentTime" to "blockTimestamp"

docs: improve wording in comments
perf: use "unchecked" for tranche calculations
refactor: rename variables

* docs: improve writing in NatSpec

* refactor: order functions and fields alphabetically

* refactor: rename variable

* docs: capitalize IDs

chore: update "filter_paths"
docs: improve writing in comments
refactor: include "streamId" in "SablierV2Lockup_WithdrawToZeroAddress"
refactor: alphabetical order

* build: bump sphinx

* test: remove ERC721Mock and use forge mock

* test: update precompiles

* chore: say "block timestamp" in comments

* refactor: update gas snapshot

test: replace "maxUint40" with "maxOfThree"

* chore: add trailing slash

* build: bump PRBMath

---------

Co-authored-by: smol-ninja <[email protected]>
Co-authored-by: andreivladbrg <[email protected]>
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