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

implement spearbit suggested optimizations #572

Merged
merged 15 commits into from
Aug 31, 2023
Merged

implement spearbit suggested optimizations #572

merged 15 commits into from
Aug 31, 2023

Conversation

jrhea
Copy link
Contributor

@jrhea jrhea commented Aug 30, 2023

resolves #476

  • reduce the number of div operations by 2 when calculating fees in openLong()

resolves #478

  • optimize return statements in _applyCheckpoint()

resolves #482

  • in query(), deltaSum.divDown(deltaTime * 1e18) = deltaSum * 1e18 / (deltaTime * 1e18) computation is the same as deltaSum / deltaTime.
  • in calculateAPRFromReserves(), To scale to one year,do mulDivDown(365 days, _positionDuration). Currently, annualizedTime is first computed as an 1e18-based percentage value
  • in calculateInitialBondReserves, FixedPointMath.ONE_18.mulDown(_timeStretch) is just _timeStretch.

@coveralls
Copy link
Collaborator

coveralls commented Aug 30, 2023

Coverage Status

coverage: 95.894% (-0.01%) from 95.904% when pulling 4a4a647 on optimizations into 662cc79 on main.

@jrhea jrhea changed the title Reduce number of operations in close long fees implement spearbit suggested optimizations Aug 30, 2023
@jrhea jrhea requested a review from jalextowle August 30, 2023 19:16
@github-actions
Copy link

github-actions bot commented Aug 30, 2023

Hyperdrive Gas Benchmark

Benchmark suite Current: 4a4a647 Previous: 662cc79 Deviation Status
addLiquidity: min 763 gas 763 gas 0% 🟰
addLiquidity: avg 45185 gas 45342 gas -0.3463%
addLiquidity: max 80502 gas 80652 gas -0.1860%
checkpoint: min 514 gas 514 gas 0% 🟰
checkpoint: avg 29398 gas 29513 gas -0.3897%
checkpoint: max 82905 gas 83031 gas -0.1518%
closeLong: min 852 gas 852 gas 0% 🟰
closeLong: avg 21528 gas 21621 gas -0.4301%
closeLong: max 87459 gas 87560 gas -0.1153%
closeShort: min 854 gas 854 gas 0% 🟰
closeShort: avg 22398 gas 22480 gas -0.3648%
closeShort: max 87717 gas 87914 gas -0.2241%
initialize: min 803 gas 803 gas 0% 🟰
initialize: avg 159484 gas 159736 gas -0.1578%
initialize: max 233224 gas 233501 gas -0.1186%
openLong: min 740 gas 740 gas 0% 🟰
openLong: avg 40795 gas 41238 gas -1.0743%
openLong: max 223505 gas 224074 gas -0.2539%
openShort: min 760 gas 760 gas 0% 🟰
openShort: avg 47627 gas 47676 gas -0.1028%
openShort: max 217404 gas 217530 gas -0.0579%
removeLiquidity: min 740 gas 740 gas 0% 🟰
removeLiquidity: avg 62278 gas 62451 gas -0.2770%
removeLiquidity: max 122657 gas 122749 gas -0.0749%

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@jalextowle jalextowle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice work!

@jrhea jrhea enabled auto-merge (squash) August 30, 2023 22:47
@jrhea jrhea merged commit 7ff8680 into main Aug 31, 2023
8 checks passed
@jrhea jrhea deleted the optimizations branch August 31, 2023 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants