-
Notifications
You must be signed in to change notification settings - Fork 409
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
Benchmarks for gas pricing #634
Conversation
Doing calcs here first... Set GasMultiplier to 280_000_000 (Wasm Gas per SDK Gas)
Set Instantiate Cost to 30_000:
Compiling Cost to 1.2 (round to 1 or 2?)
|
Interesting that we were actually overcharging previously. Mildly for Instantiate/Compile but almost 20x for Execution. Old: // Please note that all gas prices returned to wasmvm should have this multiplied.
DefaultGasMultiplier uint64 = 15_000_000
// DefaultInstanceCost is how much SDK gas we charge each time we load a WASM instance.
// Creating a new instance is costly, and this helps put a recursion limit to contracts calling contracts.
DefaultInstanceCost uint64 = 40_000
// DefaultCompileCost is how much SDK gas is charged *per byte* for compiling WASM code.
DefaultCompileCost uint64 = 2 New (leaving compile cost at 2 as it does take some disk space also): // Please note that all gas prices returned to wasmvm should have this multiplied.
DefaultGasMultiplier uint64 = 280_000_000
// DefaultInstanceCost is how much SDK gas we charge each time we load a WASM instance.
// Creating a new instance is costly, and this helps put a recursion limit to contracts calling contracts.
DefaultInstanceCost uint64 = 30_000
// DefaultCompileCost is how much SDK gas is charged *per byte* for compiling WASM code.
DefaultCompileCost uint64 = 2 |
I had a discussion with @webmaster128 and he was concerned we were possibly comparing against an outlier and this may not be the same as measuring with storage gas. The problem with storage is it can vary a lot. Size of DB, "block"/batch size, size of nodes. The only real benchmark I could find was in tendermint/iavl - most of it my code from 2017. I selected 1.000.000 entries with 16byte keys 40byte values and a batch size of 100 writes. As something to compare against.
236901ns for 2080 gas (2000 + 2*40) = 114ns/gas On the same computer, the secp256k1 measurement gave:
or 192ns/gas. Let's be nice and say the secp256k1 is charged 2x compared to storage operations. Thus, we can add such an adjustment factor in the pricing |
This gives us: Secp timing:
We can use that as the proper timing for an sdk gas. That would give us:
|
Carrying this on, it would mean InstantiateCost is 30.000*2 = 60.000 And CompileCostPerByte is 1.2 * 2 = 3 gas/byte Leaving us: // Please note that all gas prices returned to wasmvm should have this multiplied.
DefaultGasMultiplier uint64 = 140_000_000
// DefaultInstanceCost is how much SDK gas we charge each time we load a WASM instance.
// Creating a new instance is costly, and this helps put a recursion limit to contracts calling contracts.
DefaultInstanceCost uint64 = 60_000
// DefaultCompileCost is how much SDK gas is charged *per byte* for compiling WASM code.
DefaultCompileCost uint64 = 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work. added some minor nits
Prepares #566
Prepares #631
I will update prices in a new PR, once we agree on the benchmarks.