From 57348e69418b79dd666f7e869192792c9bd86ec1 Mon Sep 17 00:00:00 2001 From: Greg Hale Date: Mon, 7 Aug 2023 12:31:34 -0700 Subject: [PATCH] Use MilliGas directly --- src/Pact/Gas/Table.hs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Pact/Gas/Table.hs b/src/Pact/Gas/Table.hs index 891c61145..44068e459 100644 --- a/src/Pact/Gas/Table.hs +++ b/src/Pact/Gas/Table.hs @@ -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 @@ -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 @@ -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))