Skip to content

Commit 53d9ea1

Browse files
committed
refactor(cost-model): remove unused size parameters from Value generators
Remove unused size parameters from generatePolicyId and generateTokenName functions in the benchmarking framework. Both functions ignored their size parameters and used fixed or random sizes instead. Changes: - generatePolicyId now takes only the generator parameter (always 28 bytes) - generateTokenName now takes only the generator parameter (random 0-32 bytes) - Updated all call sites to remove the unused size arguments - Added TupleSections language extension for cleaner tuple construction - Simplified lookupCoinArgs tuple construction using applicative style
1 parent 4370918 commit 53d9ea1

File tree

1 file changed

+14
-20
lines changed
  • plutus-core/cost-model/budgeting-bench/Benchmarks

1 file changed

+14
-20
lines changed

plutus-core/cost-model/budgeting-bench/Benchmarks/Values.hs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE BlockArguments #-}
22
{-# LANGUAGE ImportQualifiedPost #-}
33
{-# LANGUAGE NumericUnderscores #-}
4+
{-# LANGUAGE TupleSections #-}
45

56
module Benchmarks.Values (makeBenchmarks) where
67

@@ -39,15 +40,12 @@ lookupCoinBenchmark gen =
3940
(lookupCoinArgs gen) -- the argument combos to generate benchmarks for
4041

4142
lookupCoinArgs :: StdGen -> [(ByteString, ByteString, Value)]
42-
lookupCoinArgs gen = runStateGen_ gen $ \g -> do
43+
lookupCoinArgs gen = runStateGen_ gen \g -> do
4344
let testValues = generateTestValues gen
4445

4546
-- Add random search keys to each test value
4647
sequence
47-
[ do
48-
searchPolicyId <- generatePolicyId 28 g
49-
searchTokenName <- generateTokenName 32 g
50-
pure (searchPolicyId, searchTokenName, value)
48+
[ (,,value) <$> generatePolicyId g <*> generateTokenName g
5149
| value <- testValues
5250
]
5351

@@ -92,8 +90,8 @@ generateRandomValueForContains
9290
-> m Value
9391
generateRandomValueForContains entryCount g = do
9492
-- Generate policies and tokens with exact entry count (realistic sizes)
95-
policyIds <- replicateM entryCount (generatePolicyId 28 g)
96-
tokenNames <- replicateM entryCount (generateTokenName 32 g)
93+
policyIds <- replicateM entryCount (generatePolicyId g)
94+
tokenNames <- replicateM entryCount (generateTokenName g)
9795

9896
let
9997
-- Create amounts (1 to 1000000)
@@ -155,10 +153,10 @@ generateConstrainedValue numPolicies tokensPerPolicy g = do
155153
then pure Value.empty
156154
else do
157155
policyIds <- -- Generate policy IDs (always 28 bytes)
158-
replicateM numPolicies (generatePolicyId 0 g)
156+
replicateM numPolicies (generatePolicyId g)
159157

160158
tokenNames <- -- Generate token names (random 0-32 bytes)
161-
replicateM tokensPerPolicy (generateTokenName 0 g)
159+
replicateM tokensPerPolicy (generateTokenName g)
162160

163161
-- Generate positive quantities (1 to 1000000)
164162
let quantity :: Int -> Int -> Integer
@@ -179,16 +177,12 @@ generateConstrainedValue numPolicies tokensPerPolicy g = do
179177
----------------------------------------------------------------------------------------------------
180178
-- Other Generators --------------------------------------------------------------------------------
181179

182-
{-| Generate policy ID of exactly 28 bytes (MintingPolicyHash size)
183-
Size parameter ignored - always generates 28 bytes
184-
-}
185-
generatePolicyId :: (StatefulGen g m) => Int -> g -> m ByteString
186-
generatePolicyId _size = uniformByteStringM 28
187-
188-
{-| Generate token name of random size (0-32 bytes)
189-
Size parameter ignored - generates random size 0-32 bytes
190-
-}
191-
generateTokenName :: (StatefulGen g m) => Int -> g -> m ByteString
192-
generateTokenName _size g = do
180+
-- | Generate policy ID of exactly 28 bytes (MintingPolicyHash size)
181+
generatePolicyId :: (StatefulGen g m) => g -> m ByteString
182+
generatePolicyId = uniformByteStringM 28
183+
184+
-- | Generate token name of random size (0-32 bytes)
185+
generateTokenName :: (StatefulGen g m) => g -> m ByteString
186+
generateTokenName g = do
193187
tokenSize <- uniformRM (0, 32) g
194188
uniformByteStringM tokenSize g

0 commit comments

Comments
 (0)