Skip to content

Commit

Permalink
Kwxm/costing/bitwise 4 (#6301)
Browse files Browse the repository at this point in the history
* Costing for new bitwise builtins

* Fix alignment problem

* Add changelog entry

* Update some CIP URLs

* Update some CIP URLs

* Remove outdated comment

* Address some review comments

* Address some review comments

* Fix for changes in main branch

* Update costing for revised version of writeBits

* Fix benchmark tests for integer division builtins

* Fix comments

* Update benchmark results for writeBits split updates

* Try removing zip in writeBits

* Remove wrapper

* Rearrange code again

* Tidying up

* Fix plutus-tx

* Make some helpers INLINEABLE

* Rearrange code again

* Simplify known type instances for 'ListCostedByLength'

---------

Co-authored-by: effectfully <effectfully@gmail.com>
  • Loading branch information
Kenneth MacKenzie and effectfully authored Jul 24, 2024
1 parent 3461df2 commit 39ae101
Show file tree
Hide file tree
Showing 39 changed files with 12,782 additions and 9,926 deletions.
12 changes: 6 additions & 6 deletions plutus-benchmark/bls12-381-costs/bench/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ import Data.ByteString qualified as BS (empty)

benchHashAndAddG1 :: EvaluationContext -> Integer -> Benchmark
benchHashAndAddG1 ctx n =
let prog = mkHashAndAddG1Script (listOfSizedByteStrings n 4)
let prog = mkHashAndAddG1Script (listOfByteStringsOfLength n 4)
in bench (show n) $ benchProgramCek ctx prog

benchHashAndAddG2 :: EvaluationContext -> Integer -> Benchmark
benchHashAndAddG2 ctx n =
let prog = mkHashAndAddG2Script (listOfSizedByteStrings n 4)
let prog = mkHashAndAddG2Script (listOfByteStringsOfLength n 4)
in bench (show n) $ benchProgramCek ctx prog

benchUncompressAndAddG1 :: EvaluationContext -> Integer -> Benchmark
benchUncompressAndAddG1 ctx n =
let prog = mkUncompressAndAddG1Script (listOfSizedByteStrings n 4)
let prog = mkUncompressAndAddG1Script (listOfByteStringsOfLength n 4)
in bench (show n) $ benchProgramCek ctx prog

benchUncompressAndAddG2 :: EvaluationContext -> Integer -> Benchmark
benchUncompressAndAddG2 ctx n =
let prog = mkUncompressAndAddG2Script (listOfSizedByteStrings n 4)
let prog = mkUncompressAndAddG2Script (listOfByteStringsOfLength n 4)
in bench (show n) $ benchProgramCek ctx prog

benchPairing :: EvaluationContext -> Benchmark
benchPairing ctx =
case listOfSizedByteStrings 4 4 of
case listOfByteStringsOfLength 4 4 of
[b1, b2, b3, b4] ->
let emptyDst = Tx.toBuiltin BS.empty
p1 = Tx.bls12_381_G1_hashToGroup (Tx.toBuiltin b1) emptyDst
Expand All @@ -46,7 +46,7 @@ benchPairing ctx =
q2 = Tx.bls12_381_G2_hashToGroup (Tx.toBuiltin b4) emptyDst
prog = mkPairingScript p1 p2 q1 q2
in bench "pairing" $ benchProgramCek ctx prog
_ -> error "Unexpected list returned by listOfSizedByteStrings"
_ -> error "Unexpected list returned by listOfByteStringsOfLength"

benchGroth16Verify :: EvaluationContext -> Benchmark
benchGroth16Verify ctx = bench "groth16Verify" $ benchProgramCek ctx mkGroth16VerifyScript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ import Prelude (IO, mapM_)

printCosts_HashAndAddG1 :: Handle -> Integer -> IO ()
printCosts_HashAndAddG1 h n =
let script = mkHashAndAddG1Script (listOfSizedByteStrings n 4)
let script = mkHashAndAddG1Script (listOfByteStringsOfLength n 4)
in printSizeStatistics h (TestSize n) script

printCosts_HashAndAddG2 :: Handle -> Integer -> IO ()
printCosts_HashAndAddG2 h n =
let script = mkHashAndAddG2Script (listOfSizedByteStrings n 4)
let script = mkHashAndAddG2Script (listOfByteStringsOfLength n 4)
in printSizeStatistics h (TestSize n) script

printCosts_UncompressAndAddG1 :: Handle -> Integer -> IO ()
printCosts_UncompressAndAddG1 h n =
let script = mkUncompressAndAddG1Script (listOfSizedByteStrings n 4)
let script = mkUncompressAndAddG1Script (listOfByteStringsOfLength n 4)
in printSizeStatistics h (TestSize n) script

printCosts_UncompressAndAddG2 :: Handle -> Integer -> IO ()
printCosts_UncompressAndAddG2 h n =
let script = mkUncompressAndAddG2Script (listOfSizedByteStrings n 4)
let script = mkUncompressAndAddG2Script (listOfByteStringsOfLength n 4)
in printSizeStatistics h (TestSize n) script

printCosts_Pairing :: Handle -> IO ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-}
module PlutusBenchmark.BLS12_381.Scripts
( checkGroth16Verify_Haskell
, listOfSizedByteStrings
, listOfByteStringsOfLength
, mkGroth16VerifyScript
, mkHashAndAddG1Script
, mkHashAndAddG2Script
Expand Down Expand Up @@ -61,9 +61,9 @@ import System.IO.Unsafe (unsafePerformIO)
import Prelude (fromIntegral)

-- Create a list containing n bytestrings of length l. This could be better.
{-# NOINLINE listOfSizedByteStrings #-}
listOfSizedByteStrings :: Integer -> Integer -> [ByteString]
listOfSizedByteStrings n l = unsafePerformIO . G.sample $
{-# NOINLINE listOfByteStringsOfLength #-}
listOfByteStringsOfLength :: Integer -> Integer -> [ByteString]
listOfByteStringsOfLength n l = unsafePerformIO . G.sample $
G.list (R.singleton $ fromIntegral n)
(G.bytes (R.singleton $ fromIntegral l))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ builtinHash :: BuiltinHashFun
builtinHash = Tx.sha2_256

-- Create a list containing n bytestrings of length l. This could be better.
{-# NOINLINE listOfSizedByteStrings #-}
listOfSizedByteStrings :: Integer -> Integer -> [ByteString]
listOfSizedByteStrings n l = unsafePerformIO . G.sample $
{-# NOINLINE listOfByteStringsOfLength #-}
listOfByteStringsOfLength :: Integer -> Integer -> [ByteString]
listOfByteStringsOfLength n l = unsafePerformIO . G.sample $
G.list (R.singleton $ fromIntegral n)
(G.bytes (R.singleton $ fromIntegral l))

Expand All @@ -94,7 +94,7 @@ mkInputs :: forall v msg .
mkInputs n toMsg hash =
Inputs $ map mkOneInput (zip seeds1 seeds2)
where seedSize = 128
(seeds1, seeds2) = splitAt n $ listOfSizedByteStrings (2*n) seedSize
(seeds1, seeds2) = splitAt n $ listOfByteStringsOfLength (2*n) seedSize
-- ^ Seeds for key generation. For some algorithms the seed has to be
-- a certain minimal size and there's a SeedBytesExhausted error if
-- it's not big enough; 128 is big enough for everything here though.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Added costing for the new bitwise builtins (see CIP-0058), which will probably become available at the Chang+1 HF.
Loading

1 comment on commit 39ae101

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Plutus Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.05.

Benchmark suite Current: 39ae101 Previous: 3461df2 Ratio
validation-auction_2-5 238.2 μs 224.6 μs 1.06
validation-crowdfunding-success-1 217.8 μs 206.4 μs 1.06
validation-crowdfunding-success-2 217.8 μs 205.9 μs 1.06
validation-crowdfunding-success-3 218 μs 205.5 μs 1.06
validation-stablecoin_2-2 201.9 μs 189.9 μs 1.06
validation-stablecoin_2-4 211.9 μs 200.2 μs 1.06
validation-token-account-2 347.9 μs 331.2 μs 1.05
nofib-knights/4x4 18440 μs 17130 μs 1.08
nofib-knights/6x6 48040 μs 44990 μs 1.07
nofib-knights/8x8 84150 μs 78850 μs 1.07
nofib-primetest/05digits 10580 μs 9963 μs 1.06
nofib-primetest/08digits 17090 μs 16190.000000000002 μs 1.06
nofib-primetest/10digits 20620 μs 19500 μs 1.06

This comment was automatically generated by workflow using github-action-benchmark.

CC: @IntersectMBO/plutus-core

Please sign in to comment.