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] Inline SatInt stuff and costing monoids #5062

Closed

Conversation

effectfully
Copy link
Contributor

Just something I noticed in the Core, needs benchmarking, so don't look here yet.

@effectfully effectfully added Performance Costing Anything relating to costs, fees, gas, etc. Don't look here yet labels Jan 22, 2023
Comment on lines 118 to 122
{-# INLINE succ #-}
succ = coerce (succ :: Int -> Int)

{-# INLINE pred #-}
pred = coerce (pred :: Int -> Int)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@michaelpj we still have this bug.

Comment on lines 88 to 91
{-# INLINE abs #-}
abs x
| x >= 0 = x
| otherwise = negate x
signum (SI x) = SI (signum x)
| x >= 0 = x
| otherwise = negate x
Copy link
Contributor Author

@effectfully effectfully Jan 22, 2023

Choose a reason for hiding this comment

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

Why is it a custom definition? How does it handle near-maximum values? Needs a few tests at the very least (unless they're already in place).

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically this stuff all got copied from safeint... which sadly means I don't have good justifications for a bunch of things :/

Copy link
Contributor

Choose a reason for hiding this comment

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

I remember thinking at the time that we should dump everything from safeInt except for the few things we actually need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've checked it and I think the current behavior is as correct as the default one:

>>> (minBound :: SatInt, negate (minBound :: SatInt))
(-9223372036854775808,9223372036854775807)
>>> (minBound :: SatInt, 0 - minBound :: SatInt)
(-9223372036854775808,9223372036854775807)
 
>>> (maxBound :: SatInt, negate (maxBound :: SatInt))
(9223372036854775807,-9223372036854775807)
>>> (maxBound :: SatInt, 0 - maxBound :: SatInt)
(9223372036854775807,-9223372036854775807)

Maybe it's a custom definition to make it faster or clearer.

Would still be great to have such tests if they're not there.

@kwxm
Copy link
Contributor

kwxm commented Jan 25, 2023

/benchmark validation

@kwxm
Copy link
Contributor

kwxm commented Jan 25, 2023

^ Just experimenting to see if running the benchmarks here uses the same machine that we use manually. Looks like they do. I've cancelled the benchmarking job now.

@effectfully effectfully force-pushed the effectfully/builtins/inline-costing-monoids branch from 4c25a04 to f999659 Compare February 22, 2023 19:20
@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

1 similar comment
@michaelpj
Copy link
Contributor

/benchmark plutus-benchmark:validation

@github-actions
Copy link
Contributor

Click here to check the status of your benchmark.

1 similar comment
@github-actions
Copy link
Contributor

Click here to check the status of your benchmark.

@effectfully effectfully force-pushed the effectfully/builtins/inline-costing-monoids branch from f999659 to aa0995c Compare March 6, 2023 00:43
@effectfully
Copy link
Contributor Author

/benchmark validation

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

Comparing benchmark results of ' validation' on 'bb6e4ff75' (base) and 'aa0995cdc' (PR)

Results table
Script bb6e4ff aa0995c Change
auction_1-1 150.3 μs 148.7 μs -1.1%
auction_1-2 653.8 μs 651.0 μs -0.4%
auction_1-3 646.9 μs 639.6 μs -1.1%
auction_1-4 198.4 μs 191.7 μs -3.4%
auction_2-1 153.5 μs 151.6 μs -1.2%
auction_2-2 652.0 μs 645.0 μs -1.1%
auction_2-3 852.4 μs 851.2 μs -0.1%
auction_2-4 646.6 μs 639.3 μs -1.1%
auction_2-5 198.7 μs 192.1 μs -3.3%
crowdfunding-success-1 182.0 μs 181.2 μs -0.4%
crowdfunding-success-2 181.5 μs 180.7 μs -0.4%
crowdfunding-success-3 181.7 μs 180.9 μs -0.4%
currency-1 236.1 μs 231.1 μs -2.1%
escrow-redeem_1-1 325.4 μs 327.3 μs +0.6%
escrow-redeem_1-2 325.3 μs 327.7 μs +0.7%
escrow-redeem_2-1 387.5 μs 385.0 μs -0.6%
escrow-redeem_2-2 388.4 μs 386.7 μs -0.4%
escrow-redeem_2-3 387.2 μs 387.2 μs 0.0%
escrow-refund-1 135.5 μs 133.1 μs -1.8%
future-increase-margin-1 235.7 μs 230.6 μs -2.2%
future-increase-margin-2 514.3 μs 518.6 μs +0.8%
future-increase-margin-3 515.8 μs 517.8 μs +0.4%
future-increase-margin-4 491.2 μs 488.3 μs -0.6%
future-increase-margin-5 859.4 μs 850.2 μs -1.1%
future-pay-out-1 236.3 μs 229.9 μs -2.7%
future-pay-out-2 516.6 μs 518.0 μs +0.3%
future-pay-out-3 516.8 μs 518.1 μs +0.3%
future-pay-out-4 855.7 μs 853.6 μs -0.2%
future-settle-early-1 236.8 μs 230.9 μs -2.5%
future-settle-early-2 519.4 μs 517.1 μs -0.4%
future-settle-early-3 517.8 μs 517.2 μs -0.1%
future-settle-early-4 644.4 μs 634.1 μs -1.6%
game-sm-success_1-1 381.3 μs 375.8 μs -1.4%
game-sm-success_1-2 171.0 μs 168.0 μs -1.8%
game-sm-success_1-3 642.5 μs 637.4 μs -0.8%
game-sm-success_1-4 197.2 μs 195.0 μs -1.1%
game-sm-success_2-1 375.4 μs 373.9 μs -0.4%
game-sm-success_2-2 170.7 μs 168.3 μs -1.4%
game-sm-success_2-3 641.9 μs 637.0 μs -0.8%
game-sm-success_2-4 196.9 μs 195.3 μs -0.8%
game-sm-success_2-5 641.7 μs 638.0 μs -0.6%
game-sm-success_2-6 197.0 μs 195.0 μs -1.0%
multisig-sm-1 391.5 μs 391.0 μs -0.1%
multisig-sm-2 382.9 μs 376.0 μs -1.8%
multisig-sm-3 379.4 μs 386.5 μs +1.9%
multisig-sm-4 388.9 μs 383.3 μs -1.4%
multisig-sm-5 566.8 μs 560.4 μs -1.1%
multisig-sm-6 391.8 μs 390.7 μs -0.3%
multisig-sm-7 383.6 μs 376.5 μs -1.9%
multisig-sm-8 382.3 μs 386.1 μs +1.0%
multisig-sm-9 388.1 μs 385.6 μs -0.6%
multisig-sm-10 566.9 μs 559.3 μs -1.3%
ping-pong-1 317.6 μs 314.9 μs -0.9%
ping-pong-2 318.9 μs 316.6 μs -0.7%
ping-pong_2-1 183.4 μs 183.4 μs 0.0%
prism-1 142.3 μs 140.8 μs -1.1%
prism-2 399.4 μs 399.7 μs +0.1%
prism-3 343.4 μs 334.0 μs -2.7%
pubkey-1 120.6 μs 117.9 μs -2.2%
stablecoin_1-1 964.5 μs 947.3 μs -1.8%
stablecoin_1-2 166.6 μs 162.8 μs -2.3%
stablecoin_1-3 1.100 ms 1.085 ms -1.4%
stablecoin_1-4 174.7 μs 174.5 μs -0.1%
stablecoin_1-5 1.389 ms 1.358 ms -2.2%
stablecoin_1-6 217.9 μs 213.4 μs -2.1%
stablecoin_2-1 963.4 μs 952.4 μs -1.1%
stablecoin_2-2 167.0 μs 162.3 μs -2.8%
stablecoin_2-3 1.099 ms 1.085 ms -1.3%
stablecoin_2-4 174.9 μs 174.1 μs -0.5%
token-account-1 173.9 μs 169.9 μs -2.3%
token-account-2 313.1 μs 313.1 μs 0.0%
uniswap-1 398.9 μs 397.5 μs -0.4%
uniswap-2 203.4 μs 202.2 μs -0.6%
uniswap-3 1.766 ms 1.738 ms -1.6%
uniswap-4 288.7 μs 278.9 μs -3.4%
uniswap-5 1.142 ms 1.119 ms -2.0%
uniswap-6 278.0 μs 269.7 μs -3.0%
vesting-1 344.5 μs 341.2 μs -1.0%

@effectfully effectfully force-pushed the effectfully/builtins/inline-costing-monoids branch from aa0995c to 58b360e Compare March 6, 2023 04:17
@effectfully
Copy link
Contributor Author

/benchmark validation

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

Comparing benchmark results of ' validation' on 'bb6e4ff75' (base) and '58b360e71' (PR)

Results table
Script bb6e4ff 58b360e Change
auction_1-1 150.4 μs 150.6 μs +0.1%
auction_1-2 654.0 μs 654.6 μs +0.1%
auction_1-3 648.3 μs 647.1 μs -0.2%
auction_1-4 200.1 μs 196.1 μs -2.0%
auction_2-1 155.1 μs 154.2 μs -0.6%
auction_2-2 662.5 μs 659.0 μs -0.5%
auction_2-3 854.3 μs 863.3 μs +1.1%
auction_2-4 649.9 μs 647.6 μs -0.4%
auction_2-5 199.2 μs 195.6 μs -1.8%
crowdfunding-success-1 183.0 μs 181.8 μs -0.7%
crowdfunding-success-2 182.4 μs 182.4 μs 0.0%
crowdfunding-success-3 183.5 μs 182.6 μs -0.5%
currency-1 238.9 μs 233.7 μs -2.2%
escrow-redeem_1-1 329.8 μs 330.0 μs +0.1%
escrow-redeem_1-2 329.9 μs 330.0 μs +0.0%
escrow-redeem_2-1 392.5 μs 388.2 μs -1.1%
escrow-redeem_2-2 394.8 μs 388.7 μs -1.5%
escrow-redeem_2-3 392.9 μs 388.6 μs -1.1%
escrow-refund-1 137.4 μs 134.1 μs -2.4%
future-increase-margin-1 239.2 μs 233.9 μs -2.2%
future-increase-margin-2 522.3 μs 524.1 μs +0.3%
future-increase-margin-3 519.6 μs 524.4 μs +0.9%
future-increase-margin-4 496.6 μs 486.3 μs -2.1%
future-increase-margin-5 868.6 μs 850.6 μs -2.1%
future-pay-out-1 238.9 μs 232.0 μs -2.9%
future-pay-out-2 522.2 μs 519.8 μs -0.5%
future-pay-out-3 520.6 μs 519.9 μs -0.1%
future-pay-out-4 861.9 μs 854.9 μs -0.8%
future-settle-early-1 239.9 μs 231.9 μs -3.3%
future-settle-early-2 520.7 μs 518.0 μs -0.5%
future-settle-early-3 522.2 μs 518.5 μs -0.7%
future-settle-early-4 648.8 μs 631.4 μs -2.7%
game-sm-success_1-1 384.9 μs 377.8 μs -1.8%
game-sm-success_1-2 172.0 μs 168.1 μs -2.3%
game-sm-success_1-3 652.8 μs 642.6 μs -1.6%
game-sm-success_1-4 199.4 μs 195.0 μs -2.2%
game-sm-success_2-1 382.7 μs 376.2 μs -1.7%
game-sm-success_2-2 172.3 μs 168.3 μs -2.3%
game-sm-success_2-3 651.4 μs 643.5 μs -1.2%
game-sm-success_2-4 198.3 μs 195.0 μs -1.7%
game-sm-success_2-5 651.0 μs 644.2 μs -1.0%
game-sm-success_2-6 199.2 μs 195.8 μs -1.7%
multisig-sm-1 399.1 μs 394.1 μs -1.3%
multisig-sm-2 388.0 μs 377.3 μs -2.8%
multisig-sm-3 390.2 μs 387.7 μs -0.6%
multisig-sm-4 398.3 μs 384.6 μs -3.4%
multisig-sm-5 574.1 μs 564.7 μs -1.6%
multisig-sm-6 393.9 μs 392.0 μs -0.5%
multisig-sm-7 390.1 μs 377.3 μs -3.3%
multisig-sm-8 389.9 μs 387.5 μs -0.6%
multisig-sm-9 394.9 μs 386.5 μs -2.1%
multisig-sm-10 574.6 μs 559.6 μs -2.6%
ping-pong-1 323.5 μs 316.1 μs -2.3%
ping-pong-2 325.4 μs 318.5 μs -2.1%
ping-pong_2-1 185.6 μs 184.6 μs -0.5%
prism-1 143.3 μs 140.8 μs -1.7%
prism-2 407.3 μs 401.2 μs -1.5%
prism-3 347.9 μs 335.1 μs -3.7%
pubkey-1 121.2 μs 119.2 μs -1.7%
stablecoin_1-1 978.2 μs 969.9 μs -0.8%
stablecoin_1-2 168.6 μs 163.4 μs -3.1%
stablecoin_1-3 1.113 ms 1.113 ms 0.0%
stablecoin_1-4 176.8 μs 175.7 μs -0.6%
stablecoin_1-5 1.407 ms 1.397 ms -0.7%
stablecoin_1-6 221.1 μs 215.1 μs -2.7%
stablecoin_2-1 979.5 μs 973.5 μs -0.6%
stablecoin_2-2 168.3 μs 163.8 μs -2.7%
stablecoin_2-3 1.120 ms 1.114 ms -0.5%
stablecoin_2-4 176.6 μs 176.2 μs -0.2%
token-account-1 175.4 μs 172.4 μs -1.7%
token-account-2 316.7 μs 318.0 μs +0.4%
uniswap-1 403.8 μs 403.7 μs -0.0%
uniswap-2 205.4 μs 205.0 μs -0.2%
uniswap-3 1.795 ms 1.779 ms -0.9%
uniswap-4 292.7 μs 282.5 μs -3.5%
uniswap-5 1.156 ms 1.144 ms -1.0%
uniswap-6 280.1 μs 273.5 μs -2.4%
vesting-1 347.3 μs 345.0 μs -0.7%

@effectfully effectfully force-pushed the effectfully/builtins/inline-costing-monoids branch from 0091d3c to 8d7623b Compare March 6, 2023 18:29
@effectfully effectfully force-pushed the effectfully/builtins/inline-costing-monoids branch from 8d7623b to 232713f Compare March 6, 2023 18:40
@effectfully
Copy link
Contributor Author

/benchmark validation

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

Comparing benchmark results of ' validation' on 'bb6e4ff75' (base) and '232713f32' (PR)

Results table
Script bb6e4ff 232713f Change
auction_1-1 151.5 μs 152.0 μs +0.3%
auction_1-2 657.4 μs 640.2 μs -2.6%
auction_1-3 651.6 μs 640.9 μs -1.6%
auction_1-4 199.7 μs 198.7 μs -0.5%
auction_2-1 155.0 μs 154.7 μs -0.2%
auction_2-2 663.1 μs 639.3 μs -3.6%
auction_2-3 868.8 μs 845.9 μs -2.6%
auction_2-4 656.9 μs 641.6 μs -2.3%
auction_2-5 200.9 μs 199.0 μs -0.9%
crowdfunding-success-1 183.7 μs 184.2 μs +0.3%
crowdfunding-success-2 184.6 μs 183.8 μs -0.4%
crowdfunding-success-3 184.5 μs 183.9 μs -0.3%
currency-1 239.2 μs 231.7 μs -3.1%
escrow-redeem_1-1 330.1 μs 328.0 μs -0.6%
escrow-redeem_1-2 330.5 μs 330.1 μs -0.1%
escrow-redeem_2-1 393.7 μs 380.8 μs -3.3%
escrow-redeem_2-2 393.9 μs 379.8 μs -3.6%
escrow-redeem_2-3 393.3 μs 383.8 μs -2.4%
escrow-refund-1 137.2 μs 134.9 μs -1.7%
future-increase-margin-1 238.8 μs 233.8 μs -2.1%
future-increase-margin-2 522.0 μs 519.6 μs -0.5%
future-increase-margin-3 520.1 μs 513.8 μs -1.2%
future-increase-margin-4 497.5 μs 485.5 μs -2.4%
future-increase-margin-5 873.5 μs 844.4 μs -3.3%
future-pay-out-1 238.5 μs 231.7 μs -2.9%
future-pay-out-2 522.0 μs 514.3 μs -1.5%
future-pay-out-3 519.4 μs 514.5 μs -0.9%
future-pay-out-4 854.6 μs 844.8 μs -1.1%
future-settle-early-1 236.6 μs 232.5 μs -1.7%
future-settle-early-2 516.0 μs 516.1 μs +0.0%
future-settle-early-3 517.5 μs 517.1 μs -0.1%
future-settle-early-4 635.7 μs 630.7 μs -0.8%
game-sm-success_1-1 376.3 μs 375.4 μs -0.2%
game-sm-success_1-2 171.0 μs 173.6 μs +1.5%
game-sm-success_1-3 645.1 μs 638.0 μs -1.1%
game-sm-success_1-4 197.7 μs 200.2 μs +1.3%
game-sm-success_2-1 377.7 μs 370.8 μs -1.8%
game-sm-success_2-2 171.6 μs 171.8 μs +0.1%
game-sm-success_2-3 643.9 μs 639.4 μs -0.7%
game-sm-success_2-4 197.2 μs 201.5 μs +2.2%
game-sm-success_2-5 645.3 μs 641.0 μs -0.7%
game-sm-success_2-6 198.0 μs 201.0 μs +1.5%
multisig-sm-1 394.5 μs 393.1 μs -0.4%
multisig-sm-2 385.7 μs 383.1 μs -0.7%
multisig-sm-3 384.0 μs 388.4 μs +1.1%
multisig-sm-4 390.1 μs 391.8 μs +0.4%
multisig-sm-5 568.5 μs 565.8 μs -0.5%
multisig-sm-6 391.7 μs 389.9 μs -0.5%
multisig-sm-7 385.9 μs 384.2 μs -0.4%
multisig-sm-8 384.1 μs 386.1 μs +0.5%
multisig-sm-9 392.5 μs 392.2 μs -0.1%
multisig-sm-10 568.7 μs 568.1 μs -0.1%
ping-pong-1 319.6 μs 324.5 μs +1.5%
ping-pong-2 320.6 μs 324.9 μs +1.3%
ping-pong_2-1 183.2 μs 184.1 μs +0.5%
prism-1 142.7 μs 144.2 μs +1.1%
prism-2 402.0 μs 402.6 μs +0.1%
prism-3 348.5 μs 337.8 μs -3.1%
pubkey-1 121.3 μs 121.1 μs -0.2%
stablecoin_1-1 966.1 μs 960.0 μs -0.6%
stablecoin_1-2 168.4 μs 166.5 μs -1.1%
stablecoin_1-3 1.180 ms 1.093 ms -7.4%
stablecoin_1-4 181.0 μs 179.2 μs -1.0%
stablecoin_1-5 1.413 ms 1.374 ms -2.8%
stablecoin_1-6 220.4 μs 218.5 μs -0.9%
stablecoin_2-1 971.2 μs 957.0 μs -1.5%
stablecoin_2-2 168.3 μs 166.4 μs -1.1%
stablecoin_2-3 1.131 ms 1.089 ms -3.7%
stablecoin_2-4 176.0 μs 179.3 μs +1.9%
token-account-1 174.2 μs 172.4 μs -1.0%
token-account-2 314.3 μs 316.6 μs +0.7%
uniswap-1 405.1 μs 396.7 μs -2.1%
uniswap-2 204.1 μs 203.7 μs -0.2%
uniswap-3 1.778 ms 1.751 ms -1.5%
uniswap-4 289.2 μs 288.9 μs -0.1%
uniswap-5 1.143 ms 1.120 ms -2.0%
uniswap-6 278.0 μs 280.4 μs +0.9%
vesting-1 344.4 μs 342.0 μs -0.7%

@effectfully
Copy link
Contributor Author

/benchmark nofib

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

Comparing benchmark results of ' nofib' on 'bb6e4ff75' (base) and '232713f32' (PR)

Results table
Script bb6e4ff 232713f Change
clausify/formula1 13.45 ms 13.57 ms +0.9%
clausify/formula2 17.38 ms 17.45 ms +0.4%
clausify/formula3 48.05 ms 48.06 ms +0.0%
clausify/formula4 73.32 ms 73.72 ms +0.5%
clausify/formula5 296.7 ms 297.5 ms +0.3%
knights/4x4 52.60 ms 53.35 ms +1.4%
knights/6x6 141.8 ms 141.9 ms +0.1%
knights/8x8 234.2 ms 235.4 ms +0.5%
primetest/05digits 27.27 ms 26.49 ms -2.9%
primetest/08digits 49.94 ms 48.32 ms -3.2%
primetest/10digits 69.68 ms 67.58 ms -3.0%
primetest/20digits 146.2 ms 141.9 ms -2.9%
primetest/30digits 214.8 ms 208.8 ms -2.8%
primetest/40digits 297.4 ms 288.4 ms -3.0%
primetest/50digits 282.9 ms 275.3 ms -2.7%
queens4x4/bt 9.444 ms 9.507 ms +0.7%
queens4x4/bm 13.32 ms 13.43 ms +0.8%
queens4x4/bjbt1 11.65 ms 11.61 ms -0.3%
queens4x4/bjbt2 11.84 ms 11.93 ms +0.8%
queens4x4/fc 25.18 ms 25.17 ms -0.0%
queens5x5/bt 124.6 ms 124.5 ms -0.1%
queens5x5/bm 154.7 ms 155.5 ms +0.5%
queens5x5/bjbt1 148.5 ms 150.0 ms +1.0%
queens5x5/bjbt2 152.2 ms 153.1 ms +0.6%
queens5x5/fc 321.5 ms 318.1 ms -1.1%

@effectfully effectfully requested a review from michaelpj March 28, 2023 14:53
Copy link
Contributor

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Looks fine!

@effectfully effectfully closed this Apr 3, 2023
@effectfully effectfully deleted the effectfully/builtins/inline-costing-monoids branch April 3, 2023 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Costing Anything relating to costs, fees, gas, etc. Don't look here yet Performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants