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

⚡️ Optimize SafeCastLib again #933

Merged
merged 4 commits into from
May 11, 2024
Merged

Conversation

Vectorized
Copy link
Owner

@Vectorized Vectorized commented May 11, 2024

Description

Continued from #929.

  • Might use assembly if it results in smaller bytecode if runtime gas is the same.
    Update: looks like the code is optimal in bytecode size and runtime gas for large number of optimizer runs.
  • Rename some test bench functions for more clarity.
forge test --mp test/SafeCastLib.t.sol --mt "Bench|codesize" --optimizer-runs=4294967295

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Ran forge fmt?
  • Ran forge snapshot?
  • Ran forge test?

Pull requests with an incomplete checklist will be thrown out.

shuhuiluo and others added 4 commits May 11, 2024 20:46
* Add `testSafeCastUint256ToIntBench` function and update .gas-snapshot

A new function, testSafeCastUint256ToIntBench, was added for testing uint256 to int conversion. Also, .gas-snapshot file was updated to reflect changes in gas usage.

* Optimize `SafeCastLib` further

The check for overflow in the SafeCastLib library's typecasting functions was refactored. The conditions for triggering overflow and typecasting were reversed to improve code readability and understanding. The updated statements are also more efficient by avoiding unnecessary shift operations.

* Optimize runtime gas for large optimizer runs

* Refactor and optimize `toInt256`

* Refactor and optimize `toUint256`
@Vectorized Vectorized merged commit ab1e79d into main May 11, 2024
13 checks passed
@Vectorized Vectorized deleted the safe-cast-lib-optimize-again branch May 11, 2024 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants