Struct is very expensive as labelled here: It seems extremely expensive when storing struct type.
https://www.cryptocompare.com/coins/guides/what-is-the-gas-in-ethereum/:
sstore 100 Paid for a normal SSTORE operation (doubled or waived sometimes).
[Q] What decised to double it?
For example I have following struct defined inside a library: Following operation inside insert()
nearly cost 150,000 gas. Storing string
, uint
and byte
under the struct.
Lib.sol
library Lib {
struct job {
string hash; // string hash_index_folderType;
uint index; //
byte folderType; //
}
}
Example.sol
import "./Lib.sol"
contract Example{
using Lib for Lib.data;
function insert( string key, byte folderType ){
uint currentIndex = cluster.jobStatus[jobKey].length;
cluster.submittedJobs.push( Lib.job({hash: key, index:
currentIndex, folderType: folderType }) );
}
}
I know that storing data is the most expensive operation in an smart contract.
But as we know ether keep increasing(jumped from 50$ to 240$ which means memory cost increased 5 times out of air) and storage price keep increases rapidly for clients as well, since mining price does not decrease. So I am in search for most compact and efficient way to use memory.
=> While ether was increasing why won't gas price does not decrease for memory?
[Q] My question is related to instead of storing struct
inside library and if I store it under the same file with the insert()
exists, does it decrease the gas usage? If not: is it good idea to combine all variables by appending them into a string and store them as single string variable instead of a struct, might it help to decrease the gas usage?
As an example:
import "github.com/Arachnid/solidity-stringutils/strings.sol";
string hash_index_folderType = key.toSlice().concat(currentIndex.toSlice().concat(folderType.toSlice());