Gas cost is an important topic in smart contract development. We want to maintain the costs as low as possible to allow for more operations in a block. There is a handy gas consumption reference, but it is already over a year old (there were lots of gas optimizations in Delphinet so the example calculation is probably out of date) and the rules are quite complicated such that it might be hard to keep all of them in mind.
Questions for experienced teams and individuals that write Michelson or designing programming languages that compile to Michelson:
What are you doing to reduce gas costs?
Are there certain instructions you avoid? For example I have heard that
DIP
is expensive operation, that leads me to believe it would be better to do a combination ofDUP
,SWAP
andDIG
.What techniques are you using to analyze gas costs and determine if your optimization is truly better? Do to the stack nature of Michelson it can be expensive (time wise) to reorganize code.
When you have multiple pieces of data you need to alter (for example you want to do something like
x + y * x - z
then send it to another contract), do you start with an ideal stack order in mind or do you make something work then try to reorganize it later.Finally, any patterns you have discovered would be helpful.