Skip to content

Commit

Permalink
[Evaluation] [Performance] Strictify 'spend' (#6705)
Browse files Browse the repository at this point in the history
I used to see this:

```haskell
              $j_sXeb (x#_aWMv :: Int#) (wild1_aWMu :: Int)
                = let! { I# ipv6_sXec ~ wild3_X8 <- wild1_aWMu } in
```

and now I see this:

```haskell
              $w$j_sum7 :: Int# -> Int# -> (# State# s_sumh, () #)
              $w$j_sum7 (x#_sum1 :: Int#) (ww2_sum4 :: Int#)
```

in the GHC Core of the `spend` local function in `UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode`. It's a small but welcome improvement.
  • Loading branch information
effectfully authored Nov 26, 2024
1 parent 5eb80f3 commit 9c184a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- In #6705 made the local `spend` function faster increasing overall performance of the evaluator by 1.8%.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-- editorconfig-checker-disable-file
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
Expand Down Expand Up @@ -142,7 +143,11 @@ restricting (ExRestrictingBudget initB@(ExBudget cpuInit memInit)) = ExBudgetMod
CekM $ writeCpu cpuLeft'
CekM $ writeMem memLeft'
when (cpuLeft' < 0 || memLeft' < 0) $ do
let budgetLeft = ExBudget cpuLeft' memLeft'
let -- You'd think whether the budget is computed strictly or not before throwing
-- an error isn't important, but GHC refuses to unbox the second argument of
-- @spend@ without this bang. Bangs on @cpuLeft'@ and @memLeft'@ don't help
-- either as those are forced by 'writeCpu' and 'writeMem' anyway. Go figure.
!budgetLeft = ExBudget cpuLeft' memLeft'
throwingWithCause _EvaluationError
(OperationalEvaluationError . CekOutOfExError $ ExRestrictingBudget budgetLeft)
Nothing
Expand Down

1 comment on commit 9c184a8

@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: 9c184a8 Previous: 5eb80f3 Ratio
validation-auction_1-1 226.5 μs 176.1 μs 1.29
validation-auction_1-2 740.4 μs 574.5 μs 1.29
validation-auction_2-2 593.8 μs 543.1 μs 1.09
validation-escrow-redeem_2-1 507.4 μs 378.2 μs 1.34
validation-escrow-redeem_2-2 506.6 μs 374.1 μs 1.35
validation-escrow-redeem_2-3 508.3 μs 374.5 μs 1.36
validation-escrow-refund-1 204.9 μs 151.4 μs 1.35
validation-future-increase-margin-1 254.1 μs 229.2 μs 1.11
validation-future-settle-early-4 630.9 μs 554.2 μs 1.14
validation-game-sm-success_1-1 462 μs 356.7 μs 1.30
validation-pubkey-1 159.4 μs 139.8 μs 1.14
validation-stablecoin_1-1 1070 μs 842.5 μs 1.27
validation-stablecoin_1-5 1658 μs 1253 μs 1.32
validation-stablecoin_1-6 297.1 μs 251.8 μs 1.18
validation-stablecoin_2-1 1133 μs 840.7 μs 1.35
validation-stablecoin_2-2 252.5 μs 191.6 μs 1.32
validation-decode-auction_1-1 273.7 μs 199.1 μs 1.37
validation-decode-auction_1-2 755.9 μs 549.9 μs 1.37
validation-decode-auction_1-3 732.1 μs 551.2 μs 1.33
validation-decode-auction_1-4 212.4 μs 200.5 μs 1.06
validation-decode-auction_2-1 213.2 μs 200.1 μs 1.07
validation-decode-auction_2-2 582.6 μs 549.4 μs 1.06
validation-decode-auction_2-3 584.1 μs 549.1 μs 1.06
validation-decode-auction_2-4 584.1 μs 548.9 μs 1.06
validation-decode-auction_2-5 213.4 μs 199.6 μs 1.07
validation-decode-crowdfunding-success-1 260.6 μs 242.9 μs 1.07
validation-decode-crowdfunding-success-2 260.3 μs 243.5 μs 1.07
validation-decode-crowdfunding-success-3 261.6 μs 243.1 μs 1.08
validation-decode-currency-1 258.8 μs 240.8 μs 1.07
validation-decode-escrow-redeem_1-1 431.2 μs 325.5 μs 1.32
validation-decode-escrow-redeem_1-2 451.1 μs 325.5 μs 1.39
validation-decode-escrow-redeem_2-1 451.8 μs 326.7 μs 1.38
validation-decode-escrow-redeem_2-2 453.7 μs 324.8 μs 1.40
validation-decode-escrow-redeem_2-3 446.9 μs 325.3 μs 1.37
validation-decode-escrow-refund-1 449.2 μs 325.5 μs 1.38
validation-decode-future-increase-margin-1 333.8 μs 239.9 μs 1.39
validation-decode-future-increase-margin-2 454.2 μs 327 μs 1.39
validation-decode-future-increase-margin-3 437.4 μs 347.8 μs 1.26
validation-decode-future-settle-early-1 243.2 μs 230.6 μs 1.05
validation-decode-future-settle-early-2 349.6 μs 325.9 μs 1.07
validation-decode-future-settle-early-3 368.8 μs 312.5 μs 1.18
validation-decode-future-settle-early-4 743.8 μs 670.8 μs 1.11
validation-decode-game-sm-success_1-1 568.8 μs 514.7 μs 1.11
validation-decode-game-sm-success_1-2 184.5 μs 165 μs 1.12
validation-decode-ping-pong-2 645.4 μs 490.9 μs 1.31
validation-decode-ping-pong_2-1 684.7 μs 479.5 μs 1.43
validation-decode-prism-1 226.7 μs 159.5 μs 1.42
validation-decode-prism-2 723.1 μs 505.7 μs 1.43
validation-decode-prism-3 258.5 μs 233.8 μs 1.11
validation-decode-stablecoin_1-1 932.1 μs 878.2 μs 1.06
validation-decode-stablecoin_1-2 182.9 μs 169.6 μs 1.08
validation-decode-stablecoin_1-3 940.4 μs 875.1 μs 1.07
validation-decode-stablecoin_1-4 183.9 μs 169.3 μs 1.09
validation-decode-stablecoin_1-5 931.2 μs 876.7 μs 1.06
validation-decode-stablecoin_1-6 183.8 μs 169.2 μs 1.09
validation-decode-stablecoin_2-1 930.9 μs 876.3 μs 1.06
validation-decode-stablecoin_2-2 182.1 μs 166.8 μs 1.09
validation-decode-stablecoin_2-3 933.4 μs 874.9 μs 1.07
validation-decode-uniswap-1 292.7 μs 233.8 μs 1.25
validation-decode-uniswap-2 320 μs 234.2 μs 1.37
validation-decode-uniswap-3 1026 μs 718.5 μs 1.43
validation-decode-uniswap-4 235.4 μs 179 μs 1.32
nofib-clausify/formula1 3051 μs 2747 μs 1.11
nofib-clausify/formula2 5002 μs 3764 μs 1.33
nofib-clausify/formula3 13730 μs 11370 μs 1.21
nofib-clausify/formula4 32030 μs 28510 μs 1.12
marlowe-semantics/0000020002010200020101020201000100010001020101020201010000020102 328.4 μs 307.8 μs 1.07
marlowe-semantics/0001000101000000010101000001000001010101010100000001000001010000 495.1 μs 422.3 μs 1.17

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

CC: @IntersectMBO/plutus-core

Please sign in to comment.