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] Drop 'RuntimeScheme' #4778

Merged
merged 20 commits into from
Aug 24, 2022

Conversation

effectfully
Copy link
Contributor

@effectfully effectfully commented Jul 20, 2022

Same as #4757 (at the time of writing). Just making sure I didn't screw up any git-related stuff.

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

1 similar comment
@michaelpj
Copy link
Contributor

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on '75592da88' (base) and '4490cb4c1' (PR)

Results table
Script 75592da 4490cb4 Change
auction_1-1 201.2 μs 191.0 μs -5.1%
auction_1-2 823.1 μs 791.1 μs -3.9%
auction_1-3 810.1 μs 778.6 μs -3.9%
auction_1-4 257.9 μs 243.1 μs -5.7%
auction_2-1 201.6 μs 190.7 μs -5.4%
auction_2-2 819.4 μs 791.7 μs -3.4%
auction_2-3 1.045 ms 1.009 ms -3.4%
auction_2-4 808.7 μs 781.2 μs -3.4%
auction_2-5 257.2 μs 243.5 μs -5.3%
crowdfunding-success-1 236.0 μs 224.4 μs -4.9%
crowdfunding-success-2 235.4 μs 223.5 μs -5.1%
crowdfunding-success-3 235.6 μs 223.5 μs -5.1%
currency-1 299.7 μs 289.0 μs -3.6%
escrow-redeem_1-1 429.8 μs 410.8 μs -4.4%
escrow-redeem_1-2 428.9 μs 411.3 μs -4.1%
escrow-redeem_2-1 504.2 μs 485.1 μs -3.8%
escrow-redeem_2-2 504.2 μs 483.9 μs -4.0%
escrow-redeem_2-3 503.5 μs 485.2 μs -3.6%
escrow-refund-1 177.2 μs 170.7 μs -3.7%
future-increase-margin-1 301.3 μs 288.1 μs -4.4%
future-increase-margin-2 677.6 μs 653.6 μs -3.5%
future-increase-margin-3 678.6 μs 654.0 μs -3.6%
future-increase-margin-4 638.5 μs 615.3 μs -3.6%
future-increase-margin-5 1.009 ms 976.7 μs -3.2%
future-pay-out-1 300.1 μs 288.0 μs -4.0%
future-pay-out-2 677.4 μs 651.7 μs -3.8%
future-pay-out-3 678.0 μs 653.4 μs -3.6%
future-pay-out-4 1.009 ms 977.2 μs -3.2%
future-settle-early-1 301.0 μs 288.3 μs -4.2%
future-settle-early-2 679.0 μs 651.2 μs -4.1%
future-settle-early-3 678.9 μs 652.8 μs -3.8%
future-settle-early-4 769.2 μs 744.5 μs -3.2%
game-sm-success_1-1 485.1 μs 468.1 μs -3.5%
game-sm-success_1-2 219.1 μs 208.0 μs -5.1%
game-sm-success_1-3 814.1 μs 782.4 μs -3.9%
game-sm-success_1-4 231.7 μs 243.9 μs +5.3%
game-sm-success_2-1 486.8 μs 468.4 μs -3.8%
game-sm-success_2-2 219.8 μs 207.2 μs -5.7%
game-sm-success_2-3 812.8 μs 783.5 μs -3.6%
game-sm-success_2-4 231.3 μs 243.4 μs +5.2%
game-sm-success_2-5 824.2 μs 782.5 μs -5.1%
game-sm-success_2-6 231.2 μs 243.2 μs +5.2%
multisig-sm-1 502.8 μs 485.3 μs -3.5%
multisig-sm-2 489.4 μs 472.4 μs -3.5%
multisig-sm-3 494.0 μs 475.2 μs -3.8%
multisig-sm-4 500.3 μs 482.6 μs -3.5%
multisig-sm-5 717.0 μs 693.3 μs -3.3%
multisig-sm-6 502.2 μs 484.4 μs -3.5%
multisig-sm-7 490.2 μs 472.6 μs -3.6%
multisig-sm-8 494.9 μs 475.4 μs -3.9%
multisig-sm-9 499.2 μs 484.2 μs -3.0%
multisig-sm-10 717.8 μs 693.6 μs -3.4%
ping-pong-1 409.8 μs 393.5 μs -4.0%
ping-pong-2 409.7 μs 393.8 μs -3.9%
ping-pong_2-1 239.3 μs 229.3 μs -4.2%
prism-1 183.4 μs 173.0 μs -5.7%
prism-2 521.8 μs 501.7 μs -3.9%
prism-3 441.4 μs 425.1 μs -3.7%
pubkey-1 155.4 μs 147.2 μs -5.3%
stablecoin_1-1 1.115 ms 1.066 ms -4.4%
stablecoin_1-2 215.4 μs 203.4 μs -5.6%
stablecoin_1-3 1.272 ms 1.210 ms -4.9%
stablecoin_1-4 228.2 μs 215.9 μs -5.4%
stablecoin_1-5 1.589 ms 1.494 ms -6.0%
stablecoin_1-6 282.8 μs 267.3 μs -5.5%
stablecoin_2-1 1.114 ms 1.058 ms -5.0%
stablecoin_2-2 214.7 μs 203.4 μs -5.3%
stablecoin_2-3 1.267 ms 1.203 ms -5.1%
stablecoin_2-4 227.3 μs 214.4 μs -5.7%
token-account-1 223.9 μs 212.9 μs -4.9%
token-account-2 399.4 μs 381.5 μs -4.5%
uniswap-1 513.5 μs 490.3 μs -4.5%
uniswap-2 262.5 μs 250.2 μs -4.7%
uniswap-3 2.057 ms 1.913 ms -7.0%
uniswap-4 377.4 μs 356.9 μs -5.4%
uniswap-5 1.408 ms 1.316 ms -6.5%
uniswap-6 362.8 μs 341.9 μs -5.8%
vesting-1 431.4 μs 414.1 μs -4.0%

@effectfully
Copy link
Contributor Author

^ -4%

Just making sure I didn't screw up any git-related stuff.

OK, I don't understand how our benchmarking infrastructure works. I was getting different results in a PR that didn't have any merges, but was created by branching from non-master, I guess I can't do that? Or maybe the benchmarking machine was sick or something? @michaelpj help me out

@michaelpj
Copy link
Contributor

I don't quite understand the question. Which two situations are we comparing? The benchmarking compares the base of the PR to the tip of the PR, if you pick a different base you might get different results...

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@effectfully
Copy link
Contributor Author

^ @michaelpj stuck again?

@michaelpj
Copy link
Contributor

Looks like it triggered an auto-gc and then it took too long so it got cancelled??

@michaelpj
Copy link
Contributor

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on '75592da88' (base) and '4490cb4c1' (PR)

Results table
Script 75592da 4490cb4 Change
auction_1-1 200.7 μs 190.9 μs -4.9%
auction_1-2 817.8 μs 790.2 μs -3.4%
auction_1-3 809.9 μs 777.2 μs -4.0%
auction_1-4 257.3 μs 242.8 μs -5.6%
auction_2-1 201.5 μs 190.7 μs -5.4%
auction_2-2 819.4 μs 788.6 μs -3.8%
auction_2-3 1.042 ms 1.005 ms -3.6%
auction_2-4 809.5 μs 777.4 μs -4.0%
auction_2-5 256.0 μs 243.2 μs -5.0%
crowdfunding-success-1 235.7 μs 223.5 μs -5.2%
crowdfunding-success-2 236.7 μs 224.1 μs -5.3%
crowdfunding-success-3 236.2 μs 224.2 μs -5.1%
currency-1 301.1 μs 289.5 μs -3.9%
escrow-redeem_1-1 427.7 μs 410.4 μs -4.0%
escrow-redeem_1-2 427.6 μs 410.1 μs -4.1%
escrow-redeem_2-1 501.7 μs 484.0 μs -3.5%
escrow-redeem_2-2 502.2 μs 482.4 μs -3.9%
escrow-redeem_2-3 503.1 μs 482.0 μs -4.2%
escrow-refund-1 176.7 μs 169.0 μs -4.4%
future-increase-margin-1 302.1 μs 287.6 μs -4.8%
future-increase-margin-2 681.6 μs 654.2 μs -4.0%
future-increase-margin-3 679.6 μs 653.9 μs -3.8%
future-increase-margin-4 640.1 μs 615.3 μs -3.9%
future-increase-margin-5 1.012 ms 979.0 μs -3.3%
future-pay-out-1 301.3 μs 287.6 μs -4.5%
future-pay-out-2 679.7 μs 652.0 μs -4.1%
future-pay-out-3 681.0 μs 654.9 μs -3.8%
future-pay-out-4 1.014 ms 982.6 μs -3.1%
future-settle-early-1 302.4 μs 289.3 μs -4.3%
future-settle-early-2 681.2 μs 656.1 μs -3.7%
future-settle-early-3 682.4 μs 655.3 μs -4.0%
future-settle-early-4 771.9 μs 747.0 μs -3.2%
game-sm-success_1-1 487.1 μs 467.1 μs -4.1%
game-sm-success_1-2 220.1 μs 207.6 μs -5.7%
game-sm-success_1-3 811.9 μs 782.9 μs -3.6%
game-sm-success_1-4 231.4 μs 242.6 μs +4.8%
game-sm-success_2-1 483.1 μs 465.9 μs -3.6%
game-sm-success_2-2 219.4 μs 206.6 μs -5.8%
game-sm-success_2-3 810.4 μs 780.3 μs -3.7%
game-sm-success_2-4 231.3 μs 242.4 μs +4.8%
game-sm-success_2-5 809.6 μs 780.5 μs -3.6%
game-sm-success_2-6 230.8 μs 243.3 μs +5.4%
multisig-sm-1 502.7 μs 484.0 μs -3.7%
multisig-sm-2 488.8 μs 471.2 μs -3.6%
multisig-sm-3 494.7 μs 476.9 μs -3.6%
multisig-sm-4 501.4 μs 482.4 μs -3.8%
multisig-sm-5 718.6 μs 691.2 μs -3.8%
multisig-sm-6 505.4 μs 485.0 μs -4.0%
multisig-sm-7 491.8 μs 473.5 μs -3.7%
multisig-sm-8 495.0 μs 475.9 μs -3.9%
multisig-sm-9 500.6 μs 485.3 μs -3.1%
multisig-sm-10 719.4 μs 698.8 μs -2.9%
ping-pong-1 410.7 μs 395.9 μs -3.6%
ping-pong-2 411.4 μs 395.3 μs -3.9%
ping-pong_2-1 239.4 μs 230.0 μs -3.9%
prism-1 182.8 μs 173.2 μs -5.3%
prism-2 521.3 μs 502.0 μs -3.7%
prism-3 440.7 μs 424.4 μs -3.7%
pubkey-1 154.8 μs 146.5 μs -5.4%
stablecoin_1-1 1.107 ms 1.060 ms -4.2%
stablecoin_1-2 215.0 μs 202.6 μs -5.8%
stablecoin_1-3 1.267 ms 1.206 ms -4.8%
stablecoin_1-4 227.9 μs 215.8 μs -5.3%
stablecoin_1-5 1.587 ms 1.494 ms -5.9%
stablecoin_1-6 282.8 μs 267.6 μs -5.4%
stablecoin_2-1 1.109 ms 1.060 ms -4.4%
stablecoin_2-2 215.6 μs 202.9 μs -5.9%
stablecoin_2-3 1.276 ms 1.224 ms -4.1%
stablecoin_2-4 228.5 μs 216.3 μs -5.3%
token-account-1 225.4 μs 214.6 μs -4.8%
token-account-2 400.8 μs 385.0 μs -3.9%
uniswap-1 514.4 μs 494.6 μs -3.8%
uniswap-2 263.3 μs 251.7 μs -4.4%
uniswap-3 2.061 ms 1.909 ms -7.4%
uniswap-4 377.5 μs 357.3 μs -5.4%
uniswap-5 1.404 ms 1.316 ms -6.3%
uniswap-6 363.7 μs 341.2 μs -6.2%
vesting-1 429.5 μs 412.4 μs -4.0%

@effectfully
Copy link
Contributor Author

^ still -4%

Looks like it triggered an auto-gc and then it took too long so it got cancelled??

I cancelled it after 5 hours, 'cause I wasn't sure what it was doing there.

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on '75592da88' (base) and 'ee9837130' (PR)

Results table
Script 75592da ee98371 Change
auction_1-1 201.8 μs 189.1 μs -6.3%
auction_1-2 821.5 μs 790.4 μs -3.8%
auction_1-3 812.5 μs 780.1 μs -4.0%
auction_1-4 256.8 μs 239.4 μs -6.8%
auction_2-1 202.8 μs 189.9 μs -6.4%
auction_2-2 821.9 μs 788.7 μs -4.0%
auction_2-3 1.047 ms 1.002 ms -4.3%
auction_2-4 809.0 μs 775.4 μs -4.2%
auction_2-5 257.1 μs 238.6 μs -7.2%
crowdfunding-success-1 235.3 μs 222.5 μs -5.4%
crowdfunding-success-2 235.8 μs 222.8 μs -5.5%
crowdfunding-success-3 236.1 μs 221.6 μs -6.1%
currency-1 300.2 μs 285.8 μs -4.8%
escrow-redeem_1-1 426.3 μs 410.1 μs -3.8%
escrow-redeem_1-2 429.9 μs 410.3 μs -4.6%
escrow-redeem_2-1 506.6 μs 481.3 μs -5.0%
escrow-redeem_2-2 505.1 μs 480.9 μs -4.8%
escrow-redeem_2-3 504.9 μs 481.4 μs -4.7%
escrow-refund-1 177.3 μs 168.0 μs -5.2%
future-increase-margin-1 301.5 μs 286.5 μs -5.0%
future-increase-margin-2 679.3 μs 655.0 μs -3.6%
future-increase-margin-3 681.3 μs 655.3 μs -3.8%
future-increase-margin-4 639.8 μs 617.0 μs -3.6%
future-increase-margin-5 1.009 ms 978.1 μs -3.1%
future-pay-out-1 301.4 μs 287.9 μs -4.5%
future-pay-out-2 678.2 μs 654.6 μs -3.5%
future-pay-out-3 677.7 μs 654.3 μs -3.5%
future-pay-out-4 1.007 ms 970.1 μs -3.7%
future-settle-early-1 301.4 μs 286.9 μs -4.8%
future-settle-early-2 679.4 μs 651.6 μs -4.1%
future-settle-early-3 677.9 μs 655.2 μs -3.3%
future-settle-early-4 769.6 μs 742.2 μs -3.6%
game-sm-success_1-1 484.1 μs 464.6 μs -4.0%
game-sm-success_1-2 219.4 μs 205.8 μs -6.2%
game-sm-success_1-3 811.6 μs 771.7 μs -4.9%
game-sm-success_1-4 231.8 μs 240.0 μs +3.5%
game-sm-success_2-1 486.8 μs 464.4 μs -4.6%
game-sm-success_2-2 220.3 μs 206.2 μs -6.4%
game-sm-success_2-3 812.1 μs 775.5 μs -4.5%
game-sm-success_2-4 231.3 μs 240.8 μs +4.1%
game-sm-success_2-5 810.4 μs 778.0 μs -4.0%
game-sm-success_2-6 231.5 μs 242.1 μs +4.6%
multisig-sm-1 504.1 μs 484.3 μs -3.9%
multisig-sm-2 489.7 μs 470.7 μs -3.9%
multisig-sm-3 493.8 μs 476.3 μs -3.5%
multisig-sm-4 500.5 μs 481.5 μs -3.8%
multisig-sm-5 715.3 μs 688.9 μs -3.7%
multisig-sm-6 504.0 μs 481.6 μs -4.4%
multisig-sm-7 490.4 μs 468.6 μs -4.4%
multisig-sm-8 493.9 μs 472.7 μs -4.3%
multisig-sm-9 499.9 μs 478.0 μs -4.4%
multisig-sm-10 716.6 μs 686.6 μs -4.2%
ping-pong-1 410.8 μs 389.5 μs -5.2%
ping-pong-2 410.2 μs 391.5 μs -4.6%
ping-pong_2-1 238.9 μs 227.2 μs -4.9%
prism-1 183.5 μs 170.9 μs -6.9%
prism-2 523.9 μs 499.3 μs -4.7%
prism-3 442.4 μs 418.2 μs -5.5%
pubkey-1 155.7 μs 144.2 μs -7.4%
stablecoin_1-1 1.115 ms 1.053 ms -5.6%
stablecoin_1-2 216.0 μs 200.8 μs -7.0%
stablecoin_1-3 1.274 ms 1.207 ms -5.3%
stablecoin_1-4 228.9 μs 215.6 μs -5.8%
stablecoin_1-5 1.589 ms 1.514 ms -4.7%
stablecoin_1-6 284.1 μs 267.1 μs -6.0%
stablecoin_2-1 1.109 ms 1.061 ms -4.3%
stablecoin_2-2 214.9 μs 201.6 μs -6.2%
stablecoin_2-3 1.265 ms 1.195 ms -5.5%
stablecoin_2-4 227.3 μs 214.3 μs -5.7%
token-account-1 225.0 μs 213.3 μs -5.2%
token-account-2 399.6 μs 380.6 μs -4.8%
uniswap-1 513.7 μs 490.3 μs -4.6%
uniswap-2 263.3 μs 248.3 μs -5.7%
uniswap-3 2.061 ms 1.917 ms -7.0%
uniswap-4 378.0 μs 354.3 μs -6.3%
uniswap-5 1.405 ms 1.314 ms -6.5%
uniswap-6 363.3 μs 341.2 μs -6.1%
vesting-1 430.8 μs 414.1 μs -3.9%

@effectfully effectfully force-pushed the effectfully/builtins/drop-RuntimeScheme-2 branch from ae13d53 to e4b8a5f Compare August 3, 2022 10:14
@effectfully effectfully force-pushed the effectfully/builtins/drop-RuntimeScheme-2 branch from ca3a7a5 to c57f732 Compare August 3, 2022 12:36
@effectfully effectfully force-pushed the effectfully/builtins/drop-RuntimeScheme-2 branch from c57f732 to 4c001d3 Compare August 3, 2022 12:37
@effectfully effectfully force-pushed the effectfully/builtins/drop-RuntimeScheme-2 branch from e53af8a to eb3467d Compare August 4, 2022 12:19
…to effectfully/builtins/drop-RuntimeScheme-2
@effectfully effectfully force-pushed the effectfully/builtins/drop-RuntimeScheme-2 branch from d5c2aef to 602e30d Compare August 11, 2022 00:37
class ExMemoryUsage a where
memoryUsage :: a -> ExMemory -- ^ How much memory does 'a' use?

instance (ExMemoryUsage a, ExMemoryUsage b) => ExMemoryUsage (a, b) where
memoryUsage (a, b) = 1 <> memoryUsage a <> memoryUsage b
{-# INLINE memoryUsage #-}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding those pragmas alone causes a slowdown: #4765.

I've verified it multiple times that adding them here causes a 1-2% speedup (because now they are actually inlined in the right place). Unfortunately, a git rebase wiped out the whole commit history from existence on GitHub, and so there's no way I could prove it apart from redoing the experiments, which I'm tired of.

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding those pragmas alone causes a slowdown: #4765.

I'm not sure what you mean by "alone". What's the difference between this and #4675? Is something else happening somewhere that stops the slowdown?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the other PR calls to memoryUsage don't get inlined for specific types, because in the current version of the builtin application machinery we only check memory usages of the whole CekValue provided as an argument. Meaning GHC sees the argument as a CekValue with an arbitrarily typed constant inside and thus GHC can't inline much.

With this PR we only feed properly unlifted values to costing functions, so that GHC knows the type of each of those values and can pick an appropriate ExMemoryUsage instance at runtime and inline the call to memoryUsage away.

So I don't know what causes the slowdown, but I know what causes the speedup (it was the whole point of this refactoring).

plutus-core/plutus-core/test/Evaluation/Spec.hs Outdated Show resolved Hide resolved
plutus-core/plutus-core.cabal Show resolved Hide resolved
@effectfully effectfully marked this pull request as ready for review August 11, 2022 13:53
@effectfully
Copy link
Contributor Author

Ready for review.

plutus-core/plutus-core/src/PlutusCore/Builtin/Meaning.hs Outdated Show resolved Hide resolved
plutus-core/plutus-core/src/PlutusCore/Builtin/Meaning.hs Outdated Show resolved Hide resolved
plutus-core/plutus-core/src/PlutusCore/Builtin/Meaning.hs Outdated Show resolved Hide resolved
plutus-core/plutus-core/src/PlutusCore/Builtin/Runtime.hs Outdated Show resolved Hide resolved
plutus-core/plutus-core/test/Evaluation/Spec.hs Outdated Show resolved Hide resolved
{-# INLINE toExMemory #-} -- It probably gets inlined anyway, but an explicit pragma
-- shouldn't hurt.
-- See Note [ExMemoryUsage instances for non-constants].
instance (Closed uni, uni `Everywhere` ExMemoryUsage) => ExMemoryUsage (CekValue uni fun) where
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel a bit weird about this, but I have no good reason for it.

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? It's the same old function, except as a class method now.

I would kinda like to forbid costing of CekValues in the first place and just say that if a function accepts a term whose type is a type variable, the costing function is supposed to either ignore the ExMemory of that argument or to unlift the argument and only then look at the ExMemory of the unlifted value, but I have no idea how to express that and even if we could, I think it would be too much of a complication to worth this static guarantee.

Right now I'm just keeping the old behavior and optimizing the machinery.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the reason is that before it was more explicit whereas now it feels like we could accidentally use the typeclass method on something that's not a CekValue and not notice. But I don't think this is really a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now it feels like we could accidentally use the typeclass method on something that's not a CekValue

But that's exactly what we do! We call the costing functions over the ExMemory of unlifted values now. It's just that we occasionally unlift into Opaque for polymorphic builtins, which is a wrapper around CekValue, hence why we need the instance. For Integer, Bool, SomeConstant etc we call memoryUsage directly without going through CekValue twice (once for unlifting, once for costing). It's the whole point of this PR!

Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently I have no idea what the point of this PR is ;)

@effectfully effectfully added the Costing Anything relating to costs, fees, gas, etc. label Aug 12, 2022
Copy link
Contributor

@kwxm kwxm left a comment

Choose a reason for hiding this comment

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

I don't grasp all of the subtleties of what's going on here, but it looks generally OK. I'd like to understand the (unrelated to this PR) stuff I previously failed to notice in Cek.Internal properly though.

plutus-core/plutus-core/src/PlutusCore/Builtin/Runtime.hs Outdated Show resolved Hide resolved
(ToCostingType n)
-- Evaluators that ignore the entire concept of costing (e.g. the CK machine) may of course force
-- the result of the builtin application unconditionally.
data BuiltinRuntime val
Copy link
Contributor

Choose a reason for hiding this comment

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

I've never really been sure why this is called BuiltinRuntime ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'Cause it's the builtin-related stuff that is used at runtime. Name suggestions are always very welcome!

plutus-core/plutus-core/src/PlutusCore/Builtin/Runtime.hs Outdated Show resolved Hide resolved
-- 'BuiltinRuntime', so that we don't need to store it here, but somehow doing so was
-- consistently slowing evaluation down by half a percent. Might be noise, might be not, but
-- at least we know that removing this @fun@ is not helpful anyway. See this commit reversing
-- the change: https://github.com/input-output-hk/plutus/pull/4778/commits/86a3e24ca3c671cc27c6f4344da2bcd14f961706
(Term NamedDeBruijn uni fun ())
-- ^ This must be lazy. It represents the fully discharged partial application of the builtin
-- function that we're going to run when it's fully saturated. We need the 'Term' to be able
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the comment at line 213 wrong now? It says (apropos BuiltinRuntime) "The partial application and its costing function.", but that's the Term argument, no? The Term is the stuff we've got so far and the BuiltinRuntime is the stuff we're still waiting for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's hard to express...

The Term is the stuff we've got so far and the BuiltinRuntime is the stuff we're still waiting for.

So yes, Term is the partial application in Plutus and BuiltinRuntime is the stuff we're waiting for, but the previous stuff that went into BuiltinRuntime constitutes the partial application of the denotation of the builtin, it's what is stored in there. To put it differently, if you have a partial application, it means you're still waiting for more stuff to be able to compute it.

class ExMemoryUsage a where
memoryUsage :: a -> ExMemory -- ^ How much memory does 'a' use?

instance (ExMemoryUsage a, ExMemoryUsage b) => ExMemoryUsage (a, b) where
memoryUsage (a, b) = 1 <> memoryUsage a <> memoryUsage b
{-# INLINE memoryUsage #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding those pragmas alone causes a slowdown: #4765.

I'm not sure what you mean by "alone". What's the difference between this and #4675? Is something else happening somewhere that stops the slowdown?

@effectfully
Copy link
Contributor Author

Comments addressed (I think).

@michaelpj do you still find something in here confusing? Should I update the docs or something?

@effectfully
Copy link
Contributor Author

Wait, it seems like I forgot to push. One sec.

@effectfully
Copy link
Contributor Author

Wait, it seems like I forgot to push. One sec.

Done.

@effectfully effectfully merged commit 8fa59fc into master Aug 24, 2022
@effectfully effectfully deleted the effectfully/builtins/drop-RuntimeScheme-2 branch August 24, 2022 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Builtins Costing Anything relating to costs, fees, gas, etc. Performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants