Questions tagged [optimization]

Questions related to the optimization of Ethereum aspects such as gas, storage, compilers, etc.

Filter by
Sorted by
Tagged with
0
votes
1answer
19 views

Gas optimisation for my art experiment spacecans.com

so I was microdosing some research chems and the thought came to me that I need to do some artsy blockchain stuff for once. It's two tin cans floating in space that you can advertise your so-called ...
1
vote
1answer
33 views

Is the gast cost of '<=' lower than the gas cost of '<'?

I've been debating on whether I should use < or <= in a for loop. So I decided to conduct a small test and verify that their gas costs are the same. Here is my contract: pragma solidity 0.4....
1
vote
1answer
85 views

How does USDC manage to only cost 25k gas instead of 35k++ for transfer?

I am baffled why Centre's USDC only costs around 25k for token transfer instead of 35k++ like other common ERC20. For example this is Gemini USD: https://etherscan.io/tx/...
2
votes
1answer
110 views

Where can I learn to read a flow of opcodes and learn how to debug transactions?

There are many tools and visualizers to use to read through a transaction, but where can I go to learn how to understand this? Fore example, that first link has a series of opcodes (and their ...
4
votes
2answers
94 views

Why is the Eternal Storage approach still used if it hugely increases gas usage compared to storing data in structs?

I was wondering why is the eternal storage approach (first code snippet) still used? I know it's meant to make contracts upgradable but it seems too expensive to me. contract Storage { mapping(...
1
vote
0answers
108 views

Modifier to only allow access via staticcall

I'm trying to create a modifier that only allows a function to be called using staticcall. Using the view declaration in Solidity 0.5.0 guarantees that a function won't change state, but it still ...
4
votes
2answers
238 views

Do intermediate memory variables cost gas?

Example without an intermediate variable: uint startTime = 9; uint allowedTime = 7; require(now > startTime + allowedTime); Example with an intermediate variable: uint startTime = 9; uint ...
1
vote
0answers
20 views

Manually configure EVM Assembly Tag

I have read that Ethereum during the compilation splits the code into tags. The solc optimizer doesn’t optimize across tags. If we consider “1+1”, it can be optimized to 0x2 if under the same tag: /...
1
vote
1answer
74 views

Why are timestamps stored in a uint (256 bit) when they would fit in a uint64?

A (signed) 64 bit timestamp can store a date much larger than the age of the universe. On many platforms this would be a micro-optimization, but in the context of Ethereum, we want to squeeze every ...
1
vote
0answers
28 views

Does pooling make sense?

It seems that allocating storage elements is 4x as expensive in terms of gas cost than changing them. Does that mean it would make sense to pool structs and arrays, and maybe also strings, rather ...
1
vote
2answers
48 views

Supply gas from contract to execution of function

let's say I have something like this function usuallyCheapFunction() external { ... do something cheap... if(rareCondition == true) { expensiveCleanupFunction(); } } function ...
4
votes
2answers
239 views

Right way to keep track of mapping values

I'm having trouble finding the most cost efficient way to keep trace of what is stored into a mapping. I'm working on a web service that requires, to display, to get the data stored in a mapping This ...
0
votes
1answer
182 views

Solidity gas optimisation for loops

I have a function in my contract loops through the current user base (an address[]), within each loop, it performs some logic and writes some data into state user variables. The function starts to ...
1
vote
2answers
155 views

Deleting index of an array in terms of optimization for looping

I have a dapp where an admin can upload a number of cakes (20 to 30). People can come into the site and decide whether they want to buy a cake uploaded by admin. So for smart contract, I made an ...
1
vote
1answer
268 views

Private vs internal cheaper

I know that external is cheaper than public due to how arguments are parsed. Is making a function private or internal cheaper?
0
votes
1answer
55 views

Calling a mapping with array of struct. Optimization or performance recommendation?

I have a struct that has a number of fields and a mapping of StudentInfo array. struct StudentInfo { uint studentId; uint courseId; uint age; string firstName; string ...
0
votes
2answers
99 views

mapping with struct array, gas or performance issue?

I have a question regarding iterating a mapping with struct array. There is a for loop that iterates over a few thousands times trying to find a matching properties inside the struct. Ex: struct ...
0
votes
2answers
24 views

How can a Dapp store seed keys of non-HD wallets?(tumbleweed)

As the title suggests, is there a Dapp that exists to store seed keys of wallet?
2
votes
1answer
103 views

Does an Ethereum client need to download the entire state of a contract in order to use it?

A typical ERC20 token will store account balances in a mapping, something like this: mapping(address => uint) public balances; Does this mean that, to do a transaction or check a balance on this ...
0
votes
0answers
26 views

multi Key shadowing

is there anyway i can implement Multi Key Shadow in ERC20 token Smart Contract ? is there any code/ function to implement in smart contract or so ? Google can only tell me how it can implemented in ...
4
votes
1answer
234 views

Difference between unoptimized and optimized solidity code

I am trying to find a source on what the difference is between optimized and unoptimized code. My main question is what the unoptimized compiler does, especially in the sense of calling the SSTORE ...
1
vote
0answers
67 views

About using Solidity optimization

It is a well known fact that in optimizing mode compilers usually have more bugs than in non-optimizing mode. As such, do you recommend to use the Solidity compiler with or without optimization? My ...
1
vote
1answer
262 views

Loop optimization checking coordinates in a grid

I built a contract where users can set an image in a specific coordinate, that position can only have one image. The grid size is 400 height, and dynamic width (Will grow overtime) and there are 3 ...
0
votes
1answer
86 views

Can I trust Solidity compiler to replace MOD with AND when possible

According to the EVM Gas Cost Yellow Paper (can be found here): The cost of % is 5 The cost of & is 3 When x is a power of 2, the expression a % x is equivalent to a & (x - 1). If x is a ...
0
votes
1answer
813 views

Loop Optimisation for gas usage

for (uint8 i = 0; i < total; i++) { if (myarray[i].my_int >= maximum && my_array[i].my_second_int <= maximum) { result = my_array[i].id; break; } } I've been ...
1
vote
1answer
23 views

Contract Fairness Optimisation

I have designed a lottery contract which allows users to purchase tickets from a ticket pool of a given size. Once all the tickets have been allocated, the lottery is carried out and the winner ...
2
votes
0answers
132 views

Is there a “gas penalty” for using too many asserts in a contract?

I'm at a very puzzling scenario. While using Remix, I noticed that adding a few asserts has caused a significant increase in execution cost (from ~50K to ~59K). And not only did it increase the ...
0
votes
2answers
263 views

Initial sync taking well over half a week [duplicate]

I ran geth --fast --cache=1024 which was the recommended for faster syncing. It goes up to reach the maximum block once, then goes to the beginning and imports chain segments again. This second ...
7
votes
1answer
1k views

Any reason not to use Browser Solidity's “Enable Optimization”?

I found that when I had "Enable optimization" activated while writing a very simple contract with browser Solidity, it reduced a total of two SSTORE opcodes to one. That resulted in 5000 gas saved. ...
2
votes
0answers
262 views

How to setup a high performance parity RPC service?

I'd like to provide the RPC service from a parity daemon hosted in EC2. There're multiple options regarding the instance type, if it's for production, should I choose "compute optimized" or "storage ...
4
votes
2answers
305 views

Why is the jump address calculation so complex in compiled Solidity code?

I have the following simple Solidity contract: pragma solidity ^0.4.0; contract Test { function Test() { intfunc(5); } uint8 store; function intfunc (uint8 a) internal { ...
3
votes
2answers
1k views

Solidity optimizer vs LLVM optimizer

Looking at the evmjit code I noticed that the LLVM optimizer is actually used right before execution of a contract by the virtual machine. I have also noticed that the Solidity compiler has its own ...
3
votes
3answers
902 views

Binary search in Solidity arrays

I have an array that will be subject to lookup and insertion operations. It is likely that it will increase in size considerably. Does solidity offer any means of performing efficient lookup ...
5
votes
1answer
604 views

Is it reasonable to use uint128 or less to save space?

As I understand EVM operates blocks of 256 bits. So uint256 is natural size for in memory calculations. But I can't find in the documentation how it's applied to transactions and for storage. I ...
5
votes
2answers
688 views

Optimizing storage for an array of addresses

When possible, does Solidity optimize a storage array of address? For example, does address[8] take up 5 storage slots (160 bytes), or 8 storage slots? contract C { address[8] arr; } If 8 slots ...
3
votes
1answer
870 views

What optimizations does Geth's --jitvm do?

geth help has: VIRTUAL MACHINE OPTIONS: --jitvm Enable the JIT VM --forcejit Force the JIT VM to take precedence --jitcache "64" Amount of cached JIT VM programs What ...
23
votes
1answer
2k views

How does the solidity optimizer work?

The compiler for solidity supports the flag --optimize which performs some set of optimizations to the compiled solidity code, typically resulting in a reduction of gas costs. How does the optimizer ...
7
votes
2answers
574 views

Are there any best practices for optimizing computations?

As complex computations cost a lot of gas (sometimes more than actually forecasted), so are there any popular ways or techniques where I can optimize a complex computation to a simplified version of ...