Skip to content

Commit

Permalink
Merge pull request #5851 from IntersectMBO/bench-master
Browse files Browse the repository at this point in the history
bench: PlutusV3 BLST workload; DRep injection; UTxO-HD tracing config
  • Loading branch information
mgmeier authored May 28, 2024
2 parents aae82df + 6aedb41 commit 2c86220
Show file tree
Hide file tree
Showing 43 changed files with 1,386 additions and 567 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ ps: ## Plain-text list of profiles
PROFILES_BASE := default default-p2p plutus plutus-secp-ecdsa plutus-secp-schnorr oldtracing idle tracer-only
PROFILES_FAST := fast fast-p2p fast-plutus fast-notracer fast-oldtracing faststartup-24M
PROFILES_CI_TEST := ci-test ci-test-p2p ci-test-plutus ci-test-notracer ci-test-rtview ci-test-dense10
PROFILES_CI_BENCH := ci-bench ci-bench-p2p ci-bench-plutus ci-bench-plutus-secp-ecdsa ci-bench-plutus-secp-schnorr ci-bench-notracer ci-bench-rtview ci-bench-lmdb
PROFILES_CI_BENCH_DREP := ci-bench-drep
PROFILES_CI_BENCH := ci-bench ci-bench-p2p ci-bench-plutus ci-bench-plutus-secp-ecdsa ci-bench-plutus-secp-schnorr ci-bench-notracer ci-bench-rtview ci-bench-lmdb ci-bench-drep
PROFILES_CI_BENCH += ci-bench-plutusv3-blst ci-bench-plutus24
PROFILES_TRACE_BENCH := trace-bench trace-bench-notracer trace-bench-oldtracing trace-bench-rtview
PROFILES_TRACE_FULL := trace-full trace-full-rtview
PROFILES_EPOCHTRANS := epoch-transition
Expand All @@ -98,7 +98,11 @@ PROFILES_VENDOR := dish dish-plutus dish-10M dish-10M-plutus
# Cloud version of "default", "ci-test" and "ci-bench" plus value (52+explorer)
# Not all local profiles are compatible or tested (yet) with a cloud runs
PROFILES_NOMAD_PERF := default-nomadperf ci-test-nomadperf ci-bench-nomadperf value-nomadperf oldtracing-nomadperf ci-test-oldtracing-nomadperf ci-bench-oldtracing-nomadperf value-oldtracing-nomadperf
PROFILES_NOMAD_PERF += plutus-nomadperf fast-nomadperf latency-nomadperf
PROFILES_NOMAD_PERF += plutus-nomadperf plutus24-nomadperf fast-nomadperf latency-nomadperf
PROFILES_NOMAD_PERF += plutusv3-blst-nomadperf plutusv3-blst-half-nomadperf plutusv3-blst-double-nomadperf
PROFILES_NOMAD_PERF += plutus-secp-ecdsa-nomadperf plutus-secp-schnorr-nomadperf
PROFILES_NOMAD_PERF_DREP := value-drep1k-nomadperf value-drep2k-nomadperf value-drep10k-nomadperf value-drep100k-nomadperf
PROFILES_NOMAD_PERF_DREP += plutus-drep1k-nomadperf plutus-drep2k-nomadperf plutus-drep10k-nomadperf plutus-drep100k-nomadperf
PROFILES_NOMAD_PERF_NOP2P := default-nomadperf-nop2p oldtracing-nomadperf-nop2p ci-test-nomadperf-nop2p ci-bench-nomadperf-nop2p
PROFILES_NOMAD_PERF_NOP2P += value-nomadperf-nop2p value-oldtracing-nomadperf-nop2p plutus-nomadperf-nop2p fast-nomadperf-nop2p
PROFILES_NOMAD_PERFSSD := value-nomadperfssd fast-nomadperfssd latency-nomadperfssd
Expand All @@ -109,7 +113,6 @@ LOCAL_PROFILES += $(PROFILES_BASE)
LOCAL_PROFILES += $(PROFILES_FAST)
LOCAL_PROFILES += $(PROFILES_CI_TEST)
LOCAL_PROFILES += $(PROFILES_CI_BENCH)
LOCAL_PROFILES += $(PROFILES_CI_BENCH_DREP)
LOCAL_PROFILES += $(PROFILES_TRACE_BENCH)
LOCAL_PROFILES += $(PROFILES_TRACE_FULL)
LOCAL_PROFILES += $(PROFILES_EPOCHTRANS)
Expand All @@ -122,6 +125,7 @@ LOCAL_PROFILES += $(PROFILES_FORGE_STRESS_RTS)
LOCAL_PROFILES += $(PROFILES_CHAINSYNC)
LOCAL_PROFILES += $(PROFILES_VENDOR)
CLOUD_PROFILES += $(PROFILES_NOMAD_PERF)
CLOUD_PROFILES += $(PROFILES_NOMAD_PERF_DREP)
CLOUD_PROFILES += $(PROFILES_NOMAD_PERF_NOP2P)
CLOUD_PROFILES += $(PROFILES_NOMAD_PERFSSD)
CLOUD_PROFILES += $(PROFILES_UTXOSCALE_SOLO)
Expand Down
6 changes: 5 additions & 1 deletion bench/locli/src/Cardano/Report.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,22 @@ data Workload
= WValue
| WPlutusLoopCountdown
| WPlutusLoopSECP
| WPlutusLoopBLST
| WPlutusUnknown

instance ToJSON Workload where
toJSON = \case
WValue -> "value-only"
WPlutusLoopCountdown -> "Plutus countdown loop"
WPlutusLoopSECP -> "Plutus SECP loop"
WPlutusLoopBLST -> "Plutus BLST loop"
WPlutusUnknown -> "Plutus (other)"

filenameInfix :: Workload -> Text
filenameInfix = \case
WPlutusLoopCountdown -> "plutus"
WPlutusLoopSECP -> "plutus-secp"
WPlutusLoopBLST -> "plutus-blst"
WValue -> "value-only"
_ -> "unknown"

Expand Down Expand Up @@ -143,9 +146,10 @@ liftTmplRun Summary{sumWorkload=generatorProfile
case plutusLoopScript generatorProfile of
Nothing -> WValue
Just script
| script == "Loop" -> WPlutusLoopCountdown
| "Loop" `T.isPrefixOf` script -> WPlutusLoopCountdown
| script == "EcdsaSecp256k1Loop" -> WPlutusLoopSECP
| script == "SchnorrSecp256k1Loop" -> WPlutusLoopSECP
| script == "HashOntoG2AndAdd" -> WPlutusLoopBLST
| otherwise -> WPlutusUnknown
}

Expand Down
61 changes: 36 additions & 25 deletions bench/plutus-scripts-bench/app/gen-plutus.hs
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}

import Cardano.Benchmarking.PlutusScripts (findPlutusScript, encodePlutusScript)
import Cardano.Benchmarking.PlutusScripts

import qualified Data.ByteString.Lazy as LBS (hPut)
import Options.Applicative
import System.Exit (die)
import System.IO (IOMode(..), openFile, stdout)
import Data.List (sort)
import Options.Applicative
import System.Exit (die)
import System.IO (IOMode (..), openFile, stdout, hClose)

data Options = Options
{ optOut :: Maybe FilePath
, optMod :: String
} deriving (Eq, Read, Show)
data Options =
List
| Print
{ optOut :: Maybe FilePath
, optMod :: String
} deriving (Eq, Show)

opts :: Parser Options
opts = Options
<$>
optional (strOption
( long "output"
<> short 'o'
<> metavar "FILE"
<> help "Write output to FILE"
)
)
<*>
strArgument
( metavar "SCRIPT"
<> help "Write SCRIPT to output"
)
opts =
subparser $ listParser <> printParser
where
listParser = command "list" $ info (p <**> helper) $ progDesc "list available scripts"
where p = pure List

printParser = command "print" $ info (p <**> helper) $ progDesc "serialize script"
where
p = Print
<$> optional (strOption
( long "output"
<> short 'o'
<> metavar "FILE"
<> help "Write output to FILE"
))
<*> strArgument (metavar "SCRIPT" <> help "Write SCRIPT to output")

pref :: ParserPrefs
pref = prefs showHelpOnEmpty

main :: IO ()
main =
do
Options {..} <- execParser (info opts fullDesc)
main = customExecParser pref (info opts fullDesc) >>= \case
List -> mapM_ putStrLn (sort listPlutusScripts)
Print{..} -> do
s <- case findPlutusScript optMod of
Just s -> pure s
Nothing -> die $ "unable to find plutus script for `" ++ optMod ++ "'"
h <- case optOut of
Just file -> openFile file WriteMode
Nothing -> pure stdout
LBS.hPut h $ encodePlutusScript s
hClose h
18 changes: 12 additions & 6 deletions bench/plutus-scripts-bench/plutus-scripts-bench.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: plutus-scripts-bench
version: 1.0.2.1
version: 1.0.3.0
synopsis: Plutus scripts used for benchmarking
description: Plutus scripts used for benchmarking.
category: Cardano,
Expand Down Expand Up @@ -40,12 +40,17 @@ common common-definitions
ImportQualifiedPost
OverloadedStrings

-- See Plutus Tx readme for why we need the following flags:
-- -fobject-code -fno-ignore-interface-pragmas and -fno-omit-interface-pragmas
ghc-options:
-Wall -Wcompat -Wincomplete-record-updates
-Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints
-fobject-code -fno-ignore-interface-pragmas -fno-omit-interface-pragmas
-Widentities -Wnoncanonical-monad-instances

-- See Plutus Tx readme for why we need the following flags:
ghc-options:
-fno-specialise -fno-spec-constr -fno-strictness
-fno-ignore-interface-pragmas -fno-omit-interface-pragmas
-fno-unbox-strict-fields -fno-unbox-small-strict-fields
-fobject-code -fno-full-laziness

if flag(defer-plugin-errors)
ghc-options: -fplugin-opt PlutusTx.Plugin:defer-errors
Expand All @@ -66,7 +71,8 @@ library
other-modules:
Cardano.Benchmarking.PlutusScripts.CustomCall
Cardano.Benchmarking.PlutusScripts.EcdsaSecp256k1Loop
Cardano.Benchmarking.PlutusScripts.Loop
Cardano.Benchmarking.PlutusScripts.HashOntoG2AndAdd
Cardano.Benchmarking.PlutusScripts.Loop2024
Cardano.Benchmarking.PlutusScripts.LoopV3
Cardano.Benchmarking.PlutusScripts.SchnorrSecp256k1Loop

Expand All @@ -85,7 +91,7 @@ library
build-depends:
, filepath
, bytestring
, serialise
-- , serialise
, template-haskell
, text

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import Cardano.Api

import qualified Cardano.Benchmarking.PlutusScripts.CustomCall as CustomCall
import qualified Cardano.Benchmarking.PlutusScripts.EcdsaSecp256k1Loop as ECDSA
import qualified Cardano.Benchmarking.PlutusScripts.Loop as Loop
import qualified Cardano.Benchmarking.PlutusScripts.HashOntoG2AndAdd as HashG2Add
import qualified Cardano.Benchmarking.PlutusScripts.Loop2024 as Loop2024
import qualified Cardano.Benchmarking.PlutusScripts.LoopV3 as LoopV3
import qualified Cardano.Benchmarking.PlutusScripts.SchnorrSecp256k1Loop as Schnorr
import Cardano.Benchmarking.ScriptAPI
Expand All @@ -35,7 +36,8 @@ getAllScripts :: [PlutusBenchScript]
getAllScripts =
[ CustomCall.script
, ECDSA.script
, Loop.script
, HashG2Add.script
, Loop2024.script
, LoopV3.script
, Schnorr.script
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

-- | This validator script is based on the Plutus benchmark
-- 'Hash n bytestrings onto G2 and add points'
-- cf. https://github.com/IntersectMBO/plutus/blob/master/plutus-benchmark/bls12-381-costs/test/9.6/bls12-381-costs.golden

module Cardano.Benchmarking.PlutusScripts.HashOntoG2AndAdd (script) where

import Cardano.Api.Shelley (PlutusScript (..), PlutusScriptV3, PlutusScriptVersion (..),
Script (..), toScriptInAnyLang)

import Cardano.Benchmarking.ScriptAPI
import qualified PlutusLedgerApi.V3 as PlutusV3

import Prelude as Haskell (String, (.), (<$>))

import qualified Data.ByteString.Short as SBS
import GHC.ByteOrder (ByteOrder(LittleEndian))

import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import qualified PlutusTx
import PlutusTx.Prelude as Tx hiding (Semigroup (..), (.), (<$>))


scriptName :: Haskell.String
scriptName
= prepareScriptName $(LitE . StringL . loc_module <$> qLocation)

script :: PlutusBenchScript
script = mkPlutusBenchScript scriptName (toScriptInAnyLang (PlutusScript PlutusScriptV3 scriptSerialized))

{-# INLINABLE mkValidator #-}
mkValidator :: BuiltinData -> BuiltinData -> BuiltinData -> ()
mkValidator _datum red _txContext =
case PlutusV3.fromBuiltinData red of
Nothing -> Tx.traceError "invalid redeemer"
Just (n, l) ->
if n < (1000000 :: Integer) -- large number ensures same bitsize for all counter values
then traceError "redeemer is < 1000000"
else loop n l
where
hashAndAddG2 :: [BuiltinByteString] -> Integer -> BuiltinBLS12_381_G2_Element
hashAndAddG2 l i =
go l (Tx.bls12_381_G2_uncompress Tx.bls12_381_G2_compressed_zero)
where go [] !acc = acc
go (q:qs) !acc = go qs $ Tx.bls12_381_G2_add (Tx.bls12_381_G2_hashToGroup q (integerToByteString LittleEndian 0 i)) acc
loop i l
| i == 1000000 = ()
| otherwise = let !_ = hashAndAddG2 l i in loop (pred i) l

hashAndAddG2ShortBs :: SBS.ShortByteString
hashAndAddG2ShortBs = PlutusV3.serialiseCompiledCode $$(PlutusTx.compile [|| mkValidator ||])

scriptSerialized :: PlutusScript PlutusScriptV3
scriptSerialized = PlutusScriptSerialised hashAndAddG2ShortBs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- PlutusV1 must be compiled using plc 1.0
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 #-}

module Cardano.Benchmarking.PlutusScripts.Loop (script) where
module Cardano.Benchmarking.PlutusScripts.Loop2024 (script) where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax
Expand Down
17 changes: 17 additions & 0 deletions bench/tx-generator/data/EcdsaSecp256k1Loop.redeemer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"constructor": 0,
"fields": [
{
"int": 1000000
},
{
"bytes": "0392d7b94bc6a11c335a043ee1ff326b6eacee6230d3685861cd62bce350a172e0"
},
{
"bytes": "16e0bf1f85594a11e75030981c0b670370b3ad83a43f49ae58a2fd6f6513cde9"
},
{
"bytes": "5fb12954b28be6456feb080cfb8467b6f5677f62eb9ad231de7a575f4b6857512754fb5ef7e0e60e270832e7bb0e2f0dc271012fa9c46c02504aa0e798be6295"
}
]
}
24 changes: 24 additions & 0 deletions bench/tx-generator/data/HashOntoG2AndAdd.redeemer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"constructor": 0,
"fields": [
{
"int": 1000000
},
{
"list": [
{
"bytes": "714805c6"
},
{
"bytes": "c413111e"
},
{
"bytes": "2d7eb870"
},
{
"bytes": "4ecbd6a1"
}
]
}
]
}
3 changes: 3 additions & 0 deletions bench/tx-generator/data/Loop.redeemer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"int": 1000000
}
3 changes: 3 additions & 0 deletions bench/tx-generator/data/Loop2024.redeemer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"int": 1000000
}
3 changes: 3 additions & 0 deletions bench/tx-generator/data/LoopV3.redeemer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"int": 1000000
}
17 changes: 17 additions & 0 deletions bench/tx-generator/data/SchnorrSecp256k1Loop.redeemer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"constructor": 0,
"fields": [
{
"int": 1000000
},
{
"bytes": "599de3e582e2a3779208a210dfeae8f330b9af00a47a7fb22e9bb8ef596f301b"
},
{
"bytes": "30303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030"
},
{
"bytes": "5a56da88e6fd8419181dec4d3dd6997bab953d2fc71ab65e23cfc9e7e3d1a310613454a60f6703819a39fdac2a410a094442afd1fc083354443e8d8bb4461a9b"
}
]
}
1 change: 0 additions & 1 deletion bench/tx-generator/data/ecdsa-secp256k1-loop.redeemer.json

This file was deleted.

1 change: 0 additions & 1 deletion bench/tx-generator/data/loop.redeemer.json

This file was deleted.

Loading

0 comments on commit 2c86220

Please sign in to comment.