You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A DependentCost is currently measured by the formula:
$cost(x) = base + \frac{x}{\alpha}$
where:
$base$ is the minimum cost (y intercept)
$\alpha$ is units per gas: $\alpha = \frac{U}{g}$. This is the number of units that will fit into 1 gas
$x$ is the number of units acting as input to the function being measured
This works well when the operation is relatively cheap, and $\alpha$ is a large number: we can fit (process) many units $U$ into a 1 gas. Integer division of $\frac{x}{\alpha}$ will provide sane values.
When the operation is expensive enough that we can fit 1 unit into 1 gas, $\alpha$ is 1. As an operation becomes increasingly expensive, $\alpha$ approaches 0: the number of units $U$ that can fit into 1 gas becomes an increasingly smaller fraction. Because cost is stored as integers, the "resolution" of the function becomes too low: anything more expensive than 1 gas per unit is a fraction $0 < \alpha < 1$ that cannot be accurately represented with integers.
Solution
For expensive operations, we can revaluate the above formula. This formula can also be written as:
$cost(x) = base + \beta * x = \frac{1}{\alpha} * x$
where:
$base$ is the minimum cost (y intercept)
$\beta$ is the gas per unit, equivalent to the inverse of the units per gas: $\beta = \frac{1}{\alpha} = \frac{g}{U}$ is the gas per unit.
$x$ is the number of units acting as input to the function being measured
Instead of representing expensive operations as the number fractional units that can fit into 1 gas, we represent them as the quantity of gas it takes to process a single unit.
To support both cases, we must introduce the concept of light operations (operations that can process many units with 1 gas) and heavy operations (operations that require more than 1 gas to process a single unit).
Implementation details
Refactor the DependentCost struct into an enum that supports variants LightOperation and HeavyOperation
LightOperations resolve with the formula for multiple-units-per-gas: $cost(x) = base + \frac{x}{\alpha}$
HeavyOperations resolve with the formula for multiple-gas-per-unit: $cost(x) = base + \beta * x$
Update fuel-vm to use new enum for DependentCost
Update fuel-core to use new enum for DependentCost in GraphQL
Update benchmarks collection: determine whether an operation is "light" or "heavy" and output the corresponding enum in the output
The text was updated successfully, but these errors were encountered:
Problem overview
A
DependentCost
is currently measured by the formula:where:
This works well when the operation is relatively cheap, and$\alpha$ is a large number: we can fit (process) many units $U$ into a 1 gas. Integer division of $\frac{x}{\alpha}$ will provide sane values.
When the operation is expensive enough that we can fit 1 unit into 1 gas,$\alpha$ is 1. As an operation becomes increasingly expensive, $\alpha$ approaches 0: the number of units $U$ that can fit into 1 gas becomes an increasingly smaller fraction. Because cost is stored as integers, the "resolution" of the function becomes too low: anything more expensive than 1 gas per unit is a fraction $0 < \alpha < 1$ that cannot be accurately represented with integers.
Solution
For expensive operations, we can revaluate the above formula. This formula can also be written as:
where:
Instead of representing expensive operations as the number fractional units that can fit into 1 gas, we represent them as the quantity of gas it takes to process a single unit.
To support both cases, we must introduce the concept of light operations (operations that can process many units with 1 gas) and heavy operations (operations that require more than 1 gas to process a single unit).
Implementation details
DependentCost
struct into an enum that supports variantsLightOperation
andHeavyOperation
LightOperations
resolve with the formula for multiple-units-per-gas:HeavyOperations
resolve with the formula for multiple-gas-per-unit:fuel-vm
to use new enum forDependentCost
fuel-core
to use new enum forDependentCost
in GraphQLThe text was updated successfully, but these errors were encountered: