Should we change the type of the time variables? #122
Replies: 2 comments 6 replies
-
Interesting proposal! I'm tentatively in favor of implementing this - let me just double check that this doesn't introduce any bug or breaking change and that I can reproduce the gas savings you reported.
LOL. Unix cannot even go that far. Read about the Year 2038 problem.
The gas savings are high because storing anything in contract storage is expensive. Though I'm not sure that they are as high as you claim them to be - to get a more accurate picture, we might have to compare only the cases when the creation of the stream succeeds, because that's when the struct is created and the time variables are actually saved in storage. |
Beta Was this translation helpful? Give feedback.
-
This has been addressed by #132. Locking. |
Beta Was this translation helpful? Give feedback.
-
In the actual implementation of the
core
contracts we are storing in theStream
struct onlyuint256
type variables, which are expensive in terms of gas cost.https://github.com/sablierhq/v2-core/blob/c7cbed688b87facd042dfeaa869882b7a3c66dc5/src/interfaces/ISablierV2Linear.sol#L56-L66
https://github.com/sablierhq/v2-core/blob/c7cbed688b87facd042dfeaa869882b7a3c66dc5/src/interfaces/ISablierV2Pro.sol#L81-L93
I was toying with all the
uint
types that solidity has and I think the best solution is to change theuint256
type touint64
for our time variables:cliffTime
segmentMilestones
startTime
andstopTime
.The only assumption we have to make is that all timestamps can fit in
uint64
, i.e. this number 18446744073709551615, this will be true until the year ~584942417303, means it is totally safe.I've actually created a branch 0eeba8c to test the gas benefits and I was surprised to find out that this change would save us 43,212 gas in average for the
create
function in theSablierV2Linear
contract and 140,236 in theSablierV2Pro
contract.Here are some of the screenshots of the gas reports:
Before
From this commit: 3003b34
https://imgur.com/a/fooGyFr
After
From this commit: 0eeba8c
https://imgur.com/a/HoIBp0a
Beta Was this translation helpful? Give feedback.
All reactions