Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Builtins] Optimize 'MakeKnownM' #4587

Merged
merged 11 commits into from
May 11, 2022

Conversation

effectfully
Copy link
Contributor

Don't look here yet.

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on 'ffa31787c' (base) and 'baaddd21c' (PR)

Results table
Script ffa3178 baaddd2 Change
auction_1-1 227.2 μs 200.0 μs -12.0%
auction_1-2 853.2 μs 819.4 μs -4.0%
auction_1-3 849.8 μs 808.1 μs -4.9%
auction_1-4 295.7 μs 257.5 μs -12.9%
auction_2-1 228.4 μs 200.6 μs -12.2%
auction_2-2 857.4 μs 819.0 μs -4.5%
auction_2-3 1.087 ms 1.035 ms -4.8%
auction_2-4 846.7 μs 803.4 μs -5.1%
auction_2-5 292.9 μs 255.7 μs -12.7%
crowdfunding-success-1 269.8 μs 236.6 μs -12.3%
crowdfunding-success-2 269.3 μs 236.0 μs -12.4%
crowdfunding-success-3 269.7 μs 236.7 μs -12.2%
currency-1 320.1 μs 298.7 μs -6.7%
escrow-redeem_1-1 467.0 μs 426.9 μs -8.6%
escrow-redeem_1-2 466.2 μs 429.4 μs -7.9%
escrow-redeem_2-1 545.3 μs 502.6 μs -7.8%
escrow-redeem_2-2 544.0 μs 501.0 μs -7.9%
escrow-redeem_2-3 546.2 μs 503.5 μs -7.8%
escrow-refund-1 203.6 μs 179.0 μs -12.1%
future-increase-margin-1 321.1 μs 300.6 μs -6.4%
future-increase-margin-2 724.4 μs 678.5 μs -6.3%
future-increase-margin-3 725.5 μs 680.2 μs -6.2%
future-increase-margin-4 675.2 μs 633.8 μs -6.1%
future-increase-margin-5 1.049 ms 1.009 ms -3.8%
future-pay-out-1 319.9 μs 299.2 μs -6.5%
future-pay-out-2 721.7 μs 678.3 μs -6.0%
future-pay-out-3 722.7 μs 676.4 μs -6.4%
future-pay-out-4 1.044 ms 1.005 ms -3.7%
future-settle-early-1 319.8 μs 299.1 μs -6.5%
future-settle-early-2 724.5 μs 678.8 μs -6.3%
future-settle-early-3 726.0 μs 681.1 μs -6.2%
future-settle-early-4 806.1 μs 767.3 μs -4.8%
game-sm-success_1-1 521.6 μs 484.3 μs -7.2%
game-sm-success_1-2 250.8 μs 218.7 μs -12.8%
game-sm-success_1-3 853.4 μs 804.6 μs -5.7%
game-sm-success_1-4 294.6 μs 255.1 μs -13.4%
game-sm-success_2-1 524.2 μs 485.2 μs -7.4%
game-sm-success_2-2 250.5 μs 218.9 μs -12.6%
game-sm-success_2-3 847.9 μs 809.4 μs -4.5%
game-sm-success_2-4 293.6 μs 255.6 μs -12.9%
game-sm-success_2-5 844.9 μs 806.9 μs -4.5%
game-sm-success_2-6 293.0 μs 256.0 μs -12.6%
multisig-sm-1 539.2 μs 500.5 μs -7.2%
multisig-sm-2 525.5 μs 488.6 μs -7.0%
multisig-sm-3 530.8 μs 490.9 μs -7.5%
multisig-sm-4 538.1 μs 498.1 μs -7.4%
multisig-sm-5 751.9 μs 713.1 μs -5.2%
multisig-sm-6 537.6 μs 497.2 μs -7.5%
multisig-sm-7 523.9 μs 485.2 μs -7.4%
multisig-sm-8 529.9 μs 491.0 μs -7.3%
multisig-sm-9 537.5 μs 497.1 μs -7.5%
multisig-sm-10 752.8 μs 713.7 μs -5.2%
ping-pong-1 442.0 μs 407.6 μs -7.8%
ping-pong-2 442.5 μs 407.9 μs -7.8%
ping-pong_2-1 264.5 μs 239.7 μs -9.4%
prism-1 210.8 μs 182.0 μs -13.7%
prism-2 568.1 μs 522.4 μs -8.0%
prism-3 480.0 μs 438.1 μs -8.7%
pubkey-1 176.9 μs 155.0 μs -12.4%
stablecoin_1-1 1.172 ms 1.110 ms -5.3%
stablecoin_1-2 245.8 μs 213.1 μs -13.3%
stablecoin_1-3 1.339 ms 1.267 ms -5.4%
stablecoin_1-4 261.0 μs 225.7 μs -13.5%
stablecoin_1-5 1.681 ms 1.578 ms -6.1%
stablecoin_1-6 324.0 μs 279.7 μs -13.7%
stablecoin_2-1 1.173 ms 1.109 ms -5.5%
stablecoin_2-2 246.1 μs 214.0 μs -13.0%
stablecoin_2-3 1.340 ms 1.266 ms -5.5%
stablecoin_2-4 261.9 μs 225.2 μs -14.0%
token-account-1 243.5 μs 223.6 μs -8.2%
token-account-2 431.7 μs 394.6 μs -8.6%
uniswap-1 533.6 μs 506.9 μs -5.0%
uniswap-2 287.4 μs 262.6 μs -8.6%
uniswap-3 2.165 ms 2.044 ms -5.6%
uniswap-4 433.0 μs 377.5 μs -12.8%
uniswap-5 1.499 ms 1.401 ms -6.5%
uniswap-6 414.3 μs 363.6 μs -12.2%
vesting-1 462.6 μs 427.5 μs -7.6%

@kwxm
Copy link
Contributor

kwxm commented May 5, 2022

This is just getting silly now...

@effectfully
Copy link
Contributor Author

-8.27% on average.

@michaelpj
Copy link
Contributor

Disgusting.

@michaelpj
Copy link
Contributor

I'm kind of scandalized that even with a concrete monad transformer stack this is faster!

@effectfully
Copy link
Contributor Author

effectfully commented May 6, 2022

I'm kind of scandalized that even with a concrete monad transformer stack this is faster!

There are two things at play here. The obvious one is that the new monad is fully strict (now that I say that, I'm tempted to make MakeKnownM into a data family associated with MakeKnownIn, so that we can make the former fully monomorphic, but such craziness definitely deserves a separate PR, plus we'll lose the monadic interface, which is probably too much of an inconvenience). The slightly less obvious thing is that we no longer need to construct and deconstructor a tuple if there are no logs emitted, i.e. for the majority of cases.

@michaelpj
Copy link
Contributor

Okay, well I don't think we can say no to 8%, so I guess tidy it up ship it.

plus we'll lose the monadic interface

Can you do crazy stuff like this?

class (Monad (ReadKnownM uni)) => MakeKnownIn uni where
   type ReadKnownIn uni = ....

fmap _ (MakeKnownFailure logs err) = MakeKnownFailure logs err
fmap f (MakeKnownSuccess a) = MakeKnownSuccess (f a)
fmap f (MakeKnownSuccessWithLogs logs a) = MakeKnownSuccessWithLogs logs (f a)
{-# INLINE fmap #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

All these INLINE annotations seem a little risky to me. If you have any substantial do block in MakeKnownM you're going to be at risk of exponential code bloat. Maybe we should just do INLINABLE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why exponential? It's a constant factor: every call to >>= becomes, what, six pattern matches. Not too much of a deal, given that we don't do much in MakeKnownM and we want all of it to be efficient, apart from stuff in tests, but it's still not that much.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you're right, it's not exponential. It would only become so if GHC got happy with case-of-case, which it's probably too smart to do. I'd be interested to know if performance is actually worse with INLINABLE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right, it's not exponential. It would only become so if GHC got happy with case-of-case, which it's probably too smart to do.

Hm, there's something to worry about here indeed. So let's say we didn't have MakeKnownSuccessWithLogs, then

(a >>= f) >>= g

would expand into

case (case a of
        MakeKnownFailure logs err -> MakeKnownFailure logs err
        MakeKnownSuccess x        -> f x) of
    MakeKnownFailure logs err  -> MakeKnownFailure logs err
    MakeKnownSuccess y         -> g y

which would be turned by case-of-case into

case a of
    MakeKnownFailure logs err ->
        case MakeKnownFailure logs err of
            MakeKnownFailure logs err  -> MakeKnownFailure logs err
            MakeKnownSuccess y         -> g y
    MakeKnownSuccess x        ->
        case f x of
            MakeKnownFailure logs err  -> MakeKnownFailure logs err
            MakeKnownSuccess y         -> g y

which would be turned by case-of-known-constructor into

case a of
    MakeKnownFailure logs err ->
        MakeKnownFailure logs err
    MakeKnownSuccess x        ->
        case f x of
            MakeKnownFailure logs err  -> MakeKnownFailure logs err
            MakeKnownSuccess y         -> g y

which is still perfectly linear.

But we do have MakeKnownSuccessWithLogs and so it is indeed very much possible we'll get duplication in the two success cases.

But then

  1. we do want the duplication, since it's important for this stuff to be as efficient as possible
  2. we won't actually get it, because our f and g are going to be known and so the case-of-known-constructor will save us

Really, I don't think we should worry about this. Especially compared to the ridiculous code bloats with meanings of builtins inlining all the way through the pipeline at each and every step until the very construction of EvaluationContext (we won't have any problems with MakeKnownM at any step, because the denotations have always been perfectly linear due to everything being fully known).

I'd be interested to know if performance is actually worse with INLINABLE.

It probably isn't any worse, but we're building quite a house of cards with all the optimizations here, I don't want to make it any more shaky unless we have to.

@effectfully
Copy link
Contributor Author

Can you do crazy stuff like this?

class (Monad (ReadKnownM uni)) => MakeKnownIn uni where
   type ReadKnownIn uni = ....

No, I mean MakeKnownM into a fully monomorphic data type, so that it's not even of kind * -> * for Monad MakeKnownM to even type check.

@effectfully effectfully force-pushed the effectfully/builtins/optimize-MakeKnownM branch from baaddd2 to 83bbac6 Compare May 9, 2022 18:48
@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on '20eadc688' (base) and '83bbac61f' (PR)

Results table
Script 20eadc6 83bbac6 Change
auction_1-1 225.3 μs 198.6 μs -11.9%
auction_1-2 849.5 μs 819.0 μs -3.6%
auction_1-3 842.6 μs 806.7 μs -4.3%
auction_1-4 290.8 μs 255.8 μs -12.0%
auction_2-1 227.0 μs 200.7 μs -11.6%
auction_2-2 846.0 μs 819.9 μs -3.1%
auction_2-3 1.087 ms 1.040 ms -4.3%
auction_2-4 846.3 μs 804.9 μs -4.9%
auction_2-5 292.3 μs 254.7 μs -12.9%
crowdfunding-success-1 267.3 μs 233.0 μs -12.8%
crowdfunding-success-2 266.7 μs 232.9 μs -12.7%
crowdfunding-success-3 267.1 μs 232.8 μs -12.8%
currency-1 318.6 μs 295.8 μs -7.2%
escrow-redeem_1-1 461.5 μs 418.4 μs -9.3%
escrow-redeem_1-2 460.8 μs 419.6 μs -8.9%
escrow-redeem_2-1 538.9 μs 495.1 μs -8.1%
escrow-redeem_2-2 539.4 μs 493.5 μs -8.5%
escrow-redeem_2-3 538.9 μs 493.8 μs -8.4%
escrow-refund-1 198.9 μs 175.9 μs -11.6%
future-increase-margin-1 318.5 μs 297.3 μs -6.7%
future-increase-margin-2 717.9 μs 675.3 μs -5.9%
future-increase-margin-3 719.2 μs 676.3 μs -6.0%
future-increase-margin-4 671.1 μs 628.8 μs -6.3%
future-increase-margin-5 1.044 ms 1.010 ms -3.3%
future-pay-out-1 317.6 μs 298.1 μs -6.1%
future-pay-out-2 719.5 μs 674.8 μs -6.2%
future-pay-out-3 721.9 μs 675.3 μs -6.5%
future-pay-out-4 1.047 ms 1.006 ms -3.9%
future-settle-early-1 319.1 μs 298.0 μs -6.6%
future-settle-early-2 720.7 μs 674.1 μs -6.5%
future-settle-early-3 719.4 μs 673.5 μs -6.4%
future-settle-early-4 803.6 μs 765.1 μs -4.8%
game-sm-success_1-1 517.6 μs 479.5 μs -7.4%
game-sm-success_1-2 249.3 μs 218.1 μs -12.5%
game-sm-success_1-3 841.8 μs 800.7 μs -4.9%
game-sm-success_1-4 290.0 μs 253.9 μs -12.4%
game-sm-success_2-1 518.4 μs 478.8 μs -7.6%
game-sm-success_2-2 249.9 μs 218.9 μs -12.4%
game-sm-success_2-3 842.3 μs 803.7 μs -4.6%
game-sm-success_2-4 290.6 μs 254.1 μs -12.6%
game-sm-success_2-5 840.8 μs 800.8 μs -4.8%
game-sm-success_2-6 290.0 μs 253.5 μs -12.6%
multisig-sm-1 532.6 μs 494.9 μs -7.1%
multisig-sm-2 523.8 μs 484.5 μs -7.5%
multisig-sm-3 530.2 μs 491.1 μs -7.4%
multisig-sm-4 536.0 μs 494.4 μs -7.8%
multisig-sm-5 753.6 μs 717.0 μs -4.9%
multisig-sm-6 536.3 μs 498.0 μs -7.1%
multisig-sm-7 521.6 μs 483.2 μs -7.4%
multisig-sm-8 526.5 μs 489.3 μs -7.1%
multisig-sm-9 533.4 μs 494.4 μs -7.3%
multisig-sm-10 752.5 μs 714.1 μs -5.1%
ping-pong-1 438.7 μs 403.7 μs -8.0%
ping-pong-2 437.5 μs 404.6 μs -7.5%
ping-pong_2-1 259.8 μs 237.0 μs -8.8%
prism-1 208.1 μs 178.7 μs -14.1%
prism-2 562.7 μs 515.3 μs -8.4%
prism-3 477.6 μs 435.0 μs -8.9%
pubkey-1 174.9 μs 152.9 μs -12.6%
stablecoin_1-1 1.167 ms 1.111 ms -4.8%
stablecoin_1-2 243.1 μs 214.9 μs -11.6%
stablecoin_1-3 1.332 ms 1.267 ms -4.9%
stablecoin_1-4 259.8 μs 227.1 μs -12.6%
stablecoin_1-5 1.678 ms 1.586 ms -5.5%
stablecoin_1-6 321.7 μs 279.7 μs -13.1%
stablecoin_2-1 1.172 ms 1.110 ms -5.3%
stablecoin_2-2 244.1 μs 213.8 μs -12.4%
stablecoin_2-3 1.343 ms 1.260 ms -6.2%
stablecoin_2-4 259.1 μs 225.4 μs -13.0%
token-account-1 242.3 μs 222.2 μs -8.3%
token-account-2 427.8 μs 395.3 μs -7.6%
uniswap-1 531.1 μs 506.2 μs -4.7%
uniswap-2 285.0 μs 259.5 μs -8.9%
uniswap-3 2.139 ms 2.046 ms -4.3%
uniswap-4 425.9 μs 372.4 μs -12.6%
uniswap-5 1.475 ms 1.395 ms -5.4%
uniswap-6 408.1 μs 359.4 μs -11.9%
vesting-1 457.4 μs 428.1 μs -6.4%

@effectfully
Copy link
Contributor Author

-8.11% on average. Ready for review.

I'm going to try to get rid of ReadKnownM next, since now that we don't construct redundant tuples it should be fine to make it ReadKnownM = MakeKnownM.

@effectfully effectfully requested review from michaelpj, kwxm and zliu41 May 9, 2022 21:04
@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on '20eadc688' (base) and '54665b928' (PR)

Results table
Script 20eadc6 54665b9 Change
auction_1-1 225.0 μs 199.6 μs -11.3%
auction_1-2 848.8 μs 818.2 μs -3.6%
auction_1-3 844.0 μs 806.3 μs -4.5%
auction_1-4 290.5 μs 254.5 μs -12.4%
auction_2-1 225.3 μs 200.1 μs -11.2%
auction_2-2 844.0 μs 818.9 μs -3.0%
auction_2-3 1.082 ms 1.038 ms -4.1%
auction_2-4 839.7 μs 806.5 μs -4.0%
auction_2-5 290.5 μs 256.0 μs -11.9%
crowdfunding-success-1 265.2 μs 233.9 μs -11.8%
crowdfunding-success-2 265.3 μs 233.6 μs -11.9%
crowdfunding-success-3 265.5 μs 234.0 μs -11.9%
currency-1 317.9 μs 296.0 μs -6.9%
escrow-redeem_1-1 459.3 μs 420.9 μs -8.4%
escrow-redeem_1-2 459.8 μs 421.9 μs -8.2%
escrow-redeem_2-1 539.0 μs 496.3 μs -7.9%
escrow-redeem_2-2 540.5 μs 496.5 μs -8.1%
escrow-redeem_2-3 542.0 μs 496.6 μs -8.4%
escrow-refund-1 199.6 μs 177.0 μs -11.3%
future-increase-margin-1 319.2 μs 295.9 μs -7.3%
future-increase-margin-2 717.6 μs 671.1 μs -6.5%
future-increase-margin-3 717.6 μs 671.2 μs -6.5%
future-increase-margin-4 672.5 μs 624.6 μs -7.1%
future-increase-margin-5 1.047 ms 1.002 ms -4.3%
future-pay-out-1 318.5 μs 296.0 μs -7.1%
future-pay-out-2 718.0 μs 672.4 μs -6.4%
future-pay-out-3 718.1 μs 673.3 μs -6.2%
future-pay-out-4 1.040 ms 1.006 ms -3.3%
future-settle-early-1 318.0 μs 297.1 μs -6.6%
future-settle-early-2 719.2 μs 671.0 μs -6.7%
future-settle-early-3 717.4 μs 671.0 μs -6.5%
future-settle-early-4 801.1 μs 764.6 μs -4.6%
game-sm-success_1-1 517.9 μs 479.3 μs -7.5%
game-sm-success_1-2 248.7 μs 219.1 μs -11.9%
game-sm-success_1-3 844.3 μs 800.3 μs -5.2%
game-sm-success_1-4 291.2 μs 254.4 μs -12.6%
game-sm-success_2-1 519.8 μs 481.0 μs -7.5%
game-sm-success_2-2 250.0 μs 219.5 μs -12.2%
game-sm-success_2-3 846.8 μs 805.6 μs -4.9%
game-sm-success_2-4 291.3 μs 254.5 μs -12.6%
game-sm-success_2-5 843.5 μs 804.7 μs -4.6%
game-sm-success_2-6 290.5 μs 254.9 μs -12.3%
multisig-sm-1 534.3 μs 495.6 μs -7.2%
multisig-sm-2 520.9 μs 483.2 μs -7.2%
multisig-sm-3 526.8 μs 488.9 μs -7.2%
multisig-sm-4 532.1 μs 494.2 μs -7.1%
multisig-sm-5 750.9 μs 713.4 μs -5.0%
multisig-sm-6 533.7 μs 495.2 μs -7.2%
multisig-sm-7 520.5 μs 483.6 μs -7.1%
multisig-sm-8 527.0 μs 488.4 μs -7.3%
multisig-sm-9 532.6 μs 494.0 μs -7.2%
multisig-sm-10 751.4 μs 711.6 μs -5.3%
ping-pong-1 437.1 μs 403.3 μs -7.7%
ping-pong-2 436.8 μs 404.8 μs -7.3%
ping-pong_2-1 259.6 μs 237.2 μs -8.6%
prism-1 208.2 μs 178.5 μs -14.3%
prism-2 563.7 μs 516.9 μs -8.3%
prism-3 478.9 μs 436.7 μs -8.8%
pubkey-1 175.5 μs 152.8 μs -12.9%
stablecoin_1-1 1.169 ms 1.112 ms -4.9%
stablecoin_1-2 243.6 μs 213.4 μs -12.4%
stablecoin_1-3 1.333 ms 1.261 ms -5.4%
stablecoin_1-4 258.5 μs 225.7 μs -12.7%
stablecoin_1-5 1.672 ms 1.581 ms -5.4%
stablecoin_1-6 320.8 μs 280.2 μs -12.7%
stablecoin_2-1 1.166 ms 1.110 ms -4.8%
stablecoin_2-2 242.6 μs 213.7 μs -11.9%
stablecoin_2-3 1.327 ms 1.261 ms -5.0%
stablecoin_2-4 259.1 μs 226.2 μs -12.7%
token-account-1 241.5 μs 222.4 μs -7.9%
token-account-2 427.4 μs 397.1 μs -7.1%
uniswap-1 529.3 μs 508.1 μs -4.0%
uniswap-2 285.0 μs 259.2 μs -9.1%
uniswap-3 2.128 ms 2.051 ms -3.6%
uniswap-4 426.4 μs 373.1 μs -12.5%
uniswap-5 1.479 ms 1.397 ms -5.5%
uniswap-6 410.3 μs 359.6 μs -12.4%
vesting-1 459.8 μs 426.9 μs -7.2%

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on '20eadc688' (base) and 'f6845efe8' (PR)

Results table
Script 20eadc6 f6845ef Change
auction_1-1 225.4 μs 200.3 μs -11.1%
auction_1-2 848.9 μs 812.6 μs -4.3%
auction_1-3 847.8 μs 793.1 μs -6.5%
auction_1-4 292.4 μs 255.0 μs -12.8%
auction_2-1 227.0 μs 199.5 μs -12.1%
auction_2-2 849.7 μs 810.8 μs -4.6%
auction_2-3 1.086 ms 1.032 ms -5.0%
auction_2-4 843.9 μs 793.4 μs -6.0%
auction_2-5 291.3 μs 255.6 μs -12.3%
crowdfunding-success-1 266.0 μs 234.5 μs -11.8%
crowdfunding-success-2 265.7 μs 234.8 μs -11.6%
crowdfunding-success-3 266.0 μs 235.5 μs -11.5%
currency-1 318.9 μs 297.5 μs -6.7%
escrow-redeem_1-1 461.4 μs 423.2 μs -8.3%
escrow-redeem_1-2 461.2 μs 422.3 μs -8.4%
escrow-redeem_2-1 540.6 μs 495.7 μs -8.3%
escrow-redeem_2-2 539.2 μs 495.2 μs -8.2%
escrow-redeem_2-3 540.5 μs 494.7 μs -8.5%
escrow-refund-1 199.5 μs 176.2 μs -11.7%
future-increase-margin-1 319.8 μs 296.1 μs -7.4%
future-increase-margin-2 720.9 μs 671.2 μs -6.9%
future-increase-margin-3 721.7 μs 671.6 μs -6.9%
future-increase-margin-4 672.5 μs 629.9 μs -6.3%
future-increase-margin-5 1.050 ms 1.004 ms -4.4%
future-pay-out-1 319.6 μs 295.9 μs -7.4%
future-pay-out-2 719.0 μs 671.5 μs -6.6%
future-pay-out-3 718.2 μs 671.2 μs -6.5%
future-pay-out-4 1.040 ms 998.8 μs -4.0%
future-settle-early-1 318.7 μs 295.5 μs -7.3%
future-settle-early-2 718.1 μs 671.0 μs -6.6%
future-settle-early-3 717.0 μs 671.6 μs -6.3%
future-settle-early-4 800.5 μs 765.4 μs -4.4%
game-sm-success_1-1 518.0 μs 482.0 μs -6.9%
game-sm-success_1-2 249.0 μs 218.0 μs -12.4%
game-sm-success_1-3 842.6 μs 804.4 μs -4.5%
game-sm-success_1-4 289.9 μs 255.0 μs -12.0%
game-sm-success_2-1 519.8 μs 482.4 μs -7.2%
game-sm-success_2-2 250.1 μs 218.1 μs -12.8%
game-sm-success_2-3 846.8 μs 805.0 μs -4.9%
game-sm-success_2-4 291.4 μs 254.6 μs -12.6%
game-sm-success_2-5 845.2 μs 804.1 μs -4.9%
game-sm-success_2-6 289.6 μs 254.1 μs -12.3%
multisig-sm-1 534.2 μs 500.1 μs -6.4%
multisig-sm-2 521.6 μs 486.3 μs -6.8%
multisig-sm-3 526.6 μs 490.6 μs -6.8%
multisig-sm-4 532.0 μs 497.7 μs -6.4%
multisig-sm-5 750.6 μs 716.3 μs -4.6%
multisig-sm-6 534.2 μs 499.6 μs -6.5%
multisig-sm-7 520.8 μs 487.0 μs -6.5%
multisig-sm-8 528.0 μs 489.8 μs -7.2%
multisig-sm-9 533.0 μs 496.6 μs -6.8%
multisig-sm-10 751.3 μs 714.1 μs -5.0%
ping-pong-1 437.6 μs 405.9 μs -7.2%
ping-pong-2 436.4 μs 405.9 μs -7.0%
ping-pong_2-1 261.2 μs 237.3 μs -9.2%
prism-1 208.6 μs 181.8 μs -12.8%
prism-2 563.5 μs 518.0 μs -8.1%
prism-3 479.2 μs 437.0 μs -8.8%
pubkey-1 175.5 μs 154.9 μs -11.7%
stablecoin_1-1 1.172 ms 1.111 ms -5.2%
stablecoin_1-2 243.1 μs 210.7 μs -13.3%
stablecoin_1-3 1.333 ms 1.268 ms -4.9%
stablecoin_1-4 259.5 μs 225.5 μs -13.1%
stablecoin_1-5 1.673 ms 1.588 ms -5.1%
stablecoin_1-6 320.9 μs 280.4 μs -12.6%
stablecoin_2-1 1.163 ms 1.115 ms -4.1%
stablecoin_2-2 242.3 μs 211.0 μs -12.9%
stablecoin_2-3 1.336 ms 1.263 ms -5.5%
stablecoin_2-4 258.0 μs 225.4 μs -12.6%
token-account-1 241.3 μs 222.3 μs -7.9%
token-account-2 427.4 μs 396.6 μs -7.2%
uniswap-1 529.6 μs 508.8 μs -3.9%
uniswap-2 284.5 μs 259.0 μs -9.0%
uniswap-3 2.133 ms 2.046 ms -4.1%
uniswap-4 426.3 μs 374.4 μs -12.2%
uniswap-5 1.479 ms 1.393 ms -5.8%
uniswap-6 410.3 μs 360.4 μs -12.2%
vesting-1 458.6 μs 426.3 μs -7.0%

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on '20eadc688' (base) and 'f93d9df52' (PR)

Results table
Script 20eadc6 f93d9df Change
auction_1-1 225.4 μs 200.2 μs -11.2%
auction_1-2 849.3 μs 818.4 μs -3.6%
auction_1-3 843.9 μs 804.4 μs -4.7%
auction_1-4 291.3 μs 254.3 μs -12.7%
auction_2-1 226.1 μs 200.1 μs -11.5%
auction_2-2 846.6 μs 816.1 μs -3.6%
auction_2-3 1.080 ms 1.036 ms -4.1%
auction_2-4 841.1 μs 802.4 μs -4.6%
auction_2-5 290.4 μs 254.1 μs -12.5%
crowdfunding-success-1 265.3 μs 235.2 μs -11.3%
crowdfunding-success-2 265.6 μs 234.8 μs -11.6%
crowdfunding-success-3 265.7 μs 234.8 μs -11.6%
currency-1 318.0 μs 295.7 μs -7.0%
escrow-redeem_1-1 461.1 μs 421.0 μs -8.7%
escrow-redeem_1-2 460.4 μs 423.2 μs -8.1%
escrow-redeem_2-1 539.3 μs 499.0 μs -7.5%
escrow-redeem_2-2 539.5 μs 498.3 μs -7.6%
escrow-redeem_2-3 538.2 μs 497.7 μs -7.5%
escrow-refund-1 196.9 μs 178.1 μs -9.5%
future-increase-margin-1 319.5 μs 296.6 μs -7.2%
future-increase-margin-2 720.4 μs 673.6 μs -6.5%
future-increase-margin-3 721.1 μs 674.2 μs -6.5%
future-increase-margin-4 671.3 μs 625.8 μs -6.8%
future-increase-margin-5 1.050 ms 1.001 ms -4.7%
future-pay-out-1 318.9 μs 295.3 μs -7.4%
future-pay-out-2 716.6 μs 672.0 μs -6.2%
future-pay-out-3 718.7 μs 672.7 μs -6.4%
future-pay-out-4 1.044 ms 999.7 μs -4.2%
future-settle-early-1 318.5 μs 296.1 μs -7.0%
future-settle-early-2 718.1 μs 674.6 μs -6.1%
future-settle-early-3 717.9 μs 674.5 μs -6.0%
future-settle-early-4 798.7 μs 764.1 μs -4.3%
game-sm-success_1-1 517.3 μs 481.1 μs -7.0%
game-sm-success_1-2 248.6 μs 218.2 μs -12.2%
game-sm-success_1-3 841.5 μs 804.6 μs -4.4%
game-sm-success_1-4 289.4 μs 253.5 μs -12.4%
game-sm-success_2-1 518.2 μs 480.9 μs -7.2%
game-sm-success_2-2 250.2 μs 218.1 μs -12.8%
game-sm-success_2-3 844.1 μs 806.6 μs -4.4%
game-sm-success_2-4 290.6 μs 253.8 μs -12.7%
game-sm-success_2-5 843.7 μs 806.9 μs -4.4%
game-sm-success_2-6 289.1 μs 254.3 μs -12.0%
multisig-sm-1 532.8 μs 497.5 μs -6.6%
multisig-sm-2 518.9 μs 484.2 μs -6.7%
multisig-sm-3 524.3 μs 491.2 μs -6.3%
multisig-sm-4 530.5 μs 494.1 μs -6.9%
multisig-sm-5 750.2 μs 712.4 μs -5.0%
multisig-sm-6 533.1 μs 495.1 μs -7.1%
multisig-sm-7 519.3 μs 483.3 μs -6.9%
multisig-sm-8 524.4 μs 492.0 μs -6.2%
multisig-sm-9 531.0 μs 495.2 μs -6.7%
multisig-sm-10 747.9 μs 714.6 μs -4.5%
ping-pong-1 436.8 μs 406.4 μs -7.0%
ping-pong-2 435.6 μs 407.8 μs -6.4%
ping-pong_2-1 260.5 μs 238.9 μs -8.3%
prism-1 208.4 μs 179.6 μs -13.8%
prism-2 563.9 μs 518.1 μs -8.1%
prism-3 477.5 μs 437.9 μs -8.3%
pubkey-1 175.2 μs 153.1 μs -12.6%
stablecoin_1-1 1.169 ms 1.111 ms -5.0%
stablecoin_1-2 242.5 μs 213.0 μs -12.2%
stablecoin_1-3 1.330 ms 1.268 ms -4.7%
stablecoin_1-4 258.0 μs 225.4 μs -12.6%
stablecoin_1-5 1.669 ms 1.592 ms -4.6%
stablecoin_1-6 319.7 μs 279.3 μs -12.6%
stablecoin_2-1 1.160 ms 1.115 ms -3.9%
stablecoin_2-2 241.6 μs 212.4 μs -12.1%
stablecoin_2-3 1.335 ms 1.267 ms -5.1%
stablecoin_2-4 257.9 μs 226.3 μs -12.3%
token-account-1 240.6 μs 222.7 μs -7.4%
token-account-2 425.3 μs 396.6 μs -6.7%
uniswap-1 529.1 μs 506.3 μs -4.3%
uniswap-2 283.8 μs 260.3 μs -8.3%
uniswap-3 2.129 ms 2.045 ms -3.9%
uniswap-4 427.2 μs 375.3 μs -12.1%
uniswap-5 1.480 ms 1.390 ms -6.1%
uniswap-6 408.1 μs 361.3 μs -11.5%
vesting-1 457.6 μs 426.6 μs -6.8%

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on '20eadc688' (base) and 'f93d9df52' (PR)

Results table
Script 20eadc6 f93d9df Change
auction_1-1 225.8 μs 199.3 μs -11.7%
auction_1-2 848.3 μs 814.1 μs -4.0%
auction_1-3 842.5 μs 800.6 μs -5.0%
auction_1-4 290.5 μs 252.6 μs -13.0%
auction_2-1 226.0 μs 199.5 μs -11.7%
auction_2-2 843.8 μs 813.6 μs -3.6%
auction_2-3 1.082 ms 1.035 ms -4.3%
auction_2-4 843.5 μs 801.4 μs -5.0%
auction_2-5 290.9 μs 253.4 μs -12.9%
crowdfunding-success-1 265.5 μs 234.8 μs -11.6%
crowdfunding-success-2 266.1 μs 234.4 μs -11.9%
crowdfunding-success-3 265.0 μs 234.2 μs -11.6%
currency-1 317.6 μs 295.5 μs -7.0%
escrow-redeem_1-1 458.4 μs 422.2 μs -7.9%
escrow-redeem_1-2 458.9 μs 423.7 μs -7.7%
escrow-redeem_2-1 540.5 μs 497.4 μs -8.0%
escrow-redeem_2-2 542.2 μs 496.4 μs -8.4%
escrow-redeem_2-3 540.8 μs 496.6 μs -8.2%
escrow-refund-1 199.1 μs 176.4 μs -11.4%
future-increase-margin-1 319.4 μs 296.6 μs -7.1%
future-increase-margin-2 718.2 μs 671.2 μs -6.5%
future-increase-margin-3 715.0 μs 672.1 μs -6.0%
future-increase-margin-4 668.9 μs 627.6 μs -6.2%
future-increase-margin-5 1.045 ms 1.005 ms -3.8%
future-pay-out-1 317.9 μs 297.0 μs -6.6%
future-pay-out-2 716.0 μs 674.5 μs -5.8%
future-pay-out-3 715.8 μs 674.7 μs -5.7%
future-pay-out-4 1.038 ms 1.001 ms -3.6%
future-settle-early-1 318.5 μs 296.4 μs -6.9%
future-settle-early-2 717.5 μs 674.1 μs -6.0%
future-settle-early-3 716.0 μs 673.2 μs -6.0%
future-settle-early-4 799.8 μs 761.8 μs -4.8%
game-sm-success_1-1 516.9 μs 481.0 μs -6.9%
game-sm-success_1-2 249.9 μs 218.2 μs -12.7%
game-sm-success_1-3 846.6 μs 809.7 μs -4.4%
game-sm-success_1-4 290.9 μs 254.4 μs -12.5%
game-sm-success_2-1 518.7 μs 483.9 μs -6.7%
game-sm-success_2-2 249.0 μs 218.6 μs -12.2%
game-sm-success_2-3 843.2 μs 804.8 μs -4.6%
game-sm-success_2-4 290.3 μs 255.5 μs -12.0%
game-sm-success_2-5 841.4 μs 804.9 μs -4.3%
game-sm-success_2-6 290.0 μs 253.8 μs -12.5%
multisig-sm-1 532.8 μs 496.4 μs -6.8%
multisig-sm-2 522.0 μs 484.0 μs -7.3%
multisig-sm-3 527.3 μs 489.8 μs -7.1%
multisig-sm-4 533.3 μs 495.0 μs -7.2%
multisig-sm-5 752.1 μs 715.9 μs -4.8%
multisig-sm-6 533.5 μs 495.2 μs -7.2%
multisig-sm-7 521.2 μs 481.9 μs -7.5%
multisig-sm-8 526.1 μs 489.5 μs -7.0%
multisig-sm-9 533.6 μs 494.9 μs -7.3%
multisig-sm-10 753.7 μs 713.7 μs -5.3%
ping-pong-1 439.1 μs 407.9 μs -7.1%
ping-pong-2 438.8 μs 407.7 μs -7.1%
ping-pong_2-1 260.6 μs 238.4 μs -8.5%
prism-1 208.8 μs 180.3 μs -13.6%
prism-2 562.0 μs 516.3 μs -8.1%
prism-3 476.7 μs 437.2 μs -8.3%
pubkey-1 175.6 μs 152.5 μs -13.2%
stablecoin_1-1 1.166 ms 1.107 ms -5.1%
stablecoin_1-2 242.8 μs 212.0 μs -12.7%
stablecoin_1-3 1.331 ms 1.269 ms -4.7%
stablecoin_1-4 257.3 μs 225.5 μs -12.4%
stablecoin_1-5 1.665 ms 1.582 ms -5.0%
stablecoin_1-6 320.1 μs 278.6 μs -13.0%
stablecoin_2-1 1.163 ms 1.107 ms -4.8%
stablecoin_2-2 242.7 μs 213.1 μs -12.2%
stablecoin_2-3 1.334 ms 1.271 ms -4.7%
stablecoin_2-4 258.0 μs 226.0 μs -12.4%
token-account-1 241.3 μs 222.9 μs -7.6%
token-account-2 424.7 μs 395.8 μs -6.8%
uniswap-1 530.0 μs 507.9 μs -4.2%
uniswap-2 285.8 μs 259.8 μs -9.1%
uniswap-3 2.141 ms 2.035 ms -5.0%
uniswap-4 427.1 μs 374.6 μs -12.3%
uniswap-5 1.475 ms 1.392 ms -5.6%
uniswap-6 407.3 μs 361.7 μs -11.2%
vesting-1 456.0 μs 427.7 μs -6.2%

@effectfully
Copy link
Contributor Author

I've done a bunch of experimentation, mostly related to the review comments, but also this:

    default makeKnown :: KnownBuiltinType val a => a -> MakeKnownM val
    -- Everything on evaluation path has to be strict in production, so in theory we don't need to
    -- force anything here. In practice however all kinds of weird things happen in tests and @val@
    -- can be non-strict enough to cause trouble here, so we're forcing the argument. Looking at the
    -- generated Core, the forcing amounts to pulling a @case@ out of the 'fromConstant' call,
    -- which doesn't affect the overall cost and benchmarking results suggest the same.
    --
    -- Note that the value is only forced to WHNF, so care must be taken to ensure that every value
    -- of a type from the universe gets forced to NF whenever it's forced to WHNF.
    makeKnown x = pure . fromConstant . someValue $! x

All of that is finished, merging.

@effectfully effectfully enabled auto-merge (squash) May 10, 2022 23:17
@effectfully effectfully disabled auto-merge May 11, 2022 01:01
@effectfully
Copy link
Contributor Author

@michaelpj ci/hydra-eval has been pending for two hours.

@effectfully effectfully force-pushed the effectfully/builtins/optimize-MakeKnownM branch from 909627e to bd8071f Compare May 11, 2022 01:03
@effectfully effectfully enabled auto-merge (squash) May 11, 2022 01:29
@effectfully effectfully disabled auto-merge May 11, 2022 01:29
@effectfully effectfully enabled auto-merge (squash) May 11, 2022 01:43
@effectfully effectfully disabled auto-merge May 11, 2022 01:43
@michaelpj
Copy link
Contributor

It's being weird, but it does seem to have passed. Force merging.

@michaelpj michaelpj merged commit 4af22f9 into master May 11, 2022
@effectfully effectfully deleted the effectfully/builtins/optimize-MakeKnownM branch May 11, 2022 13:34
@effectfully effectfully restored the effectfully/builtins/optimize-MakeKnownM branch May 11, 2022 16:15
@effectfully effectfully deleted the effectfully/builtins/optimize-MakeKnownM branch May 11, 2022 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants