Skip to content

Commit

Permalink
Use MilliGas directly
Browse files Browse the repository at this point in the history
  • Loading branch information
imalsogreg committed Aug 7, 2023
1 parent 28d5ca4 commit 57348e6
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/Pact/Gas/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ data GasCostConfig = GasCostConfig
, _gasCostConfig_sortFactor :: Gas
, _gasCostConfig_distinctFactor :: Gas
, _gasCostConfig_concatenationFactor :: Gas
, _gasCostConfig_textConcatenationFactorOffset :: Gas -- up-front cost of text concatenation
, _gasCostConfig_textConcatenationFactorStringLen :: Gas -- additional cost of concatenation per 1K characters in the average string
, _gasCostConfig_textConcatenationFactorStrings :: Gas -- additional cost of concatenation per 1K strings
, _gasCostConfig_textConcatenationFactorOffset :: MilliGas -- up-front cost of text concatenation
, _gasCostConfig_textConcatenationFactorStringLen :: MilliGas -- additional cost of concatenation per character in the average string
, _gasCostConfig_textConcatenationFactorStrings :: MilliGas -- additional cost of concatenation per list item
, _gasCostConfig_moduleCost :: Gas
, _gasCostConfig_moduleMemberCost :: Gas
, _gasCostConfig_useModuleCost :: Gas
Expand All @@ -61,9 +61,9 @@ defaultGasConfig = GasCostConfig
, _gasCostConfig_sortFactor = 1
, _gasCostConfig_distinctFactor = 1
, _gasCostConfig_concatenationFactor = 1 -- TODO benchmark
, _gasCostConfig_textConcatenationFactorOffset = 50
, _gasCostConfig_textConcatenationFactorStringLen = 20
, _gasCostConfig_textConcatenationFactorStrings = 40
, _gasCostConfig_textConcatenationFactorOffset = MilliGas 50000
, _gasCostConfig_textConcatenationFactorStringLen = MilliGas 20
, _gasCostConfig_textConcatenationFactorStrings = MilliGas 40
, _gasCostConfig_moduleCost = 1 -- TODO benchmark
, _gasCostConfig_moduleMemberCost = 1
, _gasCostConfig_useModuleCost = 1 -- TODO benchmark
Expand Down Expand Up @@ -256,10 +256,18 @@ tableGasModel gasConfig =
gasToMilliGas $ fromIntegral n * _gasCostConfig_sortFactor gasConfig
GConcatenation i j -> gasToMilliGas $
fromIntegral (i + j) * _gasCostConfig_concatenationFactor gasConfig
GTextConcatenation nChars nStrings -> gasToMilliGas $
_gasCostConfig_textConcatenationFactorOffset gasConfig +
(fromIntegral nChars * _gasCostConfig_textConcatenationFactorStringLen gasConfig) `div` 1000 `div` fromIntegral nStrings +
(fromIntegral nStrings * _gasCostConfig_textConcatenationFactorStrings gasConfig) `div` 1000
GTextConcatenation nChars nStrings ->
let
MilliGas offsetCost = _gasCostConfig_textConcatenationFactorOffset gasConfig
MilliGas charCost = _gasCostConfig_textConcatenationFactorStringLen gasConfig
MilliGas stringCost = _gasCostConfig_textConcatenationFactorStrings gasConfig

costForAverageStringLength =
(fromIntegral nChars * charCost) `div` fromIntegral nStrings
costForNumberOfStrings =
fromIntegral nStrings * stringCost
in
MilliGas $ offsetCost + costForAverageStringLength + costForNumberOfStrings
GFoldDB -> gasToMilliGas $ _gasCostConfig_foldDBCost gasConfig
GPostRead r -> gasToMilliGas $ case r of
ReadData cols -> _gasCostConfig_readColumnCost gasConfig * fromIntegral (Map.size (_objectMap $ _rdData cols))
Expand Down

0 comments on commit 57348e6

Please sign in to comment.