Comments (9)
Update: this conversation on Twitter is related to this issue.
As per transmission11's reply there, it does look like in an older version of Solidity, x != 0
used to be more gas efficient than x > 0
.
Tagging @hrkrshnn in case he can illuminate us here?
from gas-optimizations.
I will follow up tomorrow.
from gas-optimizations.
Thanks @hrkrshnn, though no rush from my end.
from gas-optimizations.
@PaulRBerg The main difference is the use of via-ir
. There are rules for transforming these expressions into an equivalent cheaper expression. But these rules are more effective in the new compilation pipeline. The legacy codegen and its optimizer works across basic blocks of assembly. And sometimes these expressions get split across basic blocks. See: https://hrkrshnn.com/t/devconnect.pdf#page=4 for another example.
I think these expressions should have the same cost if viaIR=true
and the optimizer is enabled. Please don't hesitate to ping me again / open an issue in the original repo if that's not the case.
from gas-optimizations.
Thanks @hrkrshnn, makes sense.
What I don't understand though is that when I compiled the the code snippets above in Remix, I did not enable via-ir
.
Is it that in the latest versions of Solidity, the compiler automatically applies via-ir
to some operations, like !=
and >
?
from gas-optimizations.
@PaulRBerg via-ir is not enabled by default yet. You can expect it to be default in an upcoming breaking release. The easiest way to test would be in Foundry, by adding viaIR = true
in the toml config.
from gas-optimizations.
You can expect it to be default in an upcoming breaking release
Good to know!
via-ir is not enabled by default yet
This doesn't clear up the mystery yet of why the code snippets all yield the same gas cost even if --via-ir
is not enabled.
from gas-optimizations.
This doesn't clear up the mystery yet of why the code snippets all yield the same gas cost even if --via-ir is not enabled.
It's likely because it uses different opcodes. See https://godbolt.org/z/q8K4WGqzr
from gas-optimizations.
Thank you ser, will take a look.
from gas-optimizations.
Related Issues (17)
- Specify Solidity pragma in code snippets HOT 1
- Create docs book
- Use do while if loop should run at least once
- Separate conditions instead of combined conditions HOT 2
- Section on using assembly for gas savings
- Use mulmod over mul & div
- Enhance each optimization with further info HOT 1
- Unlinked "see why" on Proper Data Types
- Payable constructor HOT 1
- Immutable State Variables vs. Constant HOT 1
- Include greater detail as to how gas is saved for technical patterns
- Yul IR pipeline
- Uint bit-packing
- Separate general gas saving patterns and technical patterns
- ++i vs i++
- Examples with benchmarks for all gas saving patterns
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gas-optimizations.