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 'KnownBuiltinTypeIn' constraints #4380

Merged

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 '17e096548' (base) and '5581c30bf' (PR)

Script 17e0965 5581c30 Change
auction_1-1 323.0 μs 315.0 μs -2.5%
auction_1-2 1.073 ms 1.047 ms -2.4%
auction_1-3 1.071 ms 1.048 ms -2.1%
auction_1-4 421.9 μs 411.8 μs -2.4%
auction_2-1 322.5 μs 315.1 μs -2.3%
auction_2-2 1.071 ms 1.049 ms -2.1%
auction_2-3 1.354 ms 1.323 ms -2.3%
auction_2-4 1.071 ms 1.044 ms -2.5%
auction_2-5 419.9 μs 412.3 μs -1.8%
crowdfunding-success-1 377.4 μs 371.1 μs -1.7%
crowdfunding-success-2 378.5 μs 371.0 μs -2.0%
crowdfunding-success-3 377.5 μs 371.9 μs -1.5%
currency-1 415.9 μs 409.5 μs -1.5%
escrow-redeem_1-1 622.1 μs 612.5 μs -1.5%
escrow-redeem_1-2 621.6 μs 613.5 μs -1.3%
escrow-redeem_2-1 658.9 μs 714.8 μs +8.5%
escrow-redeem_2-2 655.5 μs 713.8 μs +8.9%
escrow-redeem_2-3 656.9 μs 715.5 μs +8.9%
escrow-refund-1 285.3 μs 279.6 μs -2.0%
future-increase-margin-1 417.5 μs 408.2 μs -2.2%
future-increase-margin-2 939.0 μs 918.9 μs -2.1%
future-increase-margin-3 936.7 μs 916.8 μs -2.1%
future-increase-margin-4 874.6 μs 855.6 μs -2.2%
future-increase-margin-5 1.304 ms 1.276 ms -2.1%
future-pay-out-1 416.8 μs 408.3 μs -2.0%
future-pay-out-2 933.1 μs 916.7 μs -1.8%
future-pay-out-3 933.9 μs 915.0 μs -2.0%
future-pay-out-4 1.301 ms 1.274 ms -2.1%
future-settle-early-1 416.2 μs 408.7 μs -1.8%
future-settle-early-2 937.5 μs 918.8 μs -2.0%
future-settle-early-3 934.1 μs 918.5 μs -1.7%
future-settle-early-4 1.010 ms 994.9 μs -1.5%
game-sm-success_1-1 695.5 μs 683.1 μs -1.8%
game-sm-success_1-2 358.0 μs 350.8 μs -2.0%
game-sm-success_1-3 1.078 ms 1.052 ms -2.4%
game-sm-success_1-4 420.8 μs 410.6 μs -2.4%
game-sm-success_2-1 696.4 μs 684.6 μs -1.7%
game-sm-success_2-2 358.9 μs 353.2 μs -1.6%
game-sm-success_2-3 1.077 ms 1.056 ms -1.9%
game-sm-success_2-4 419.9 μs 411.6 μs -2.0%
game-sm-success_2-5 1.079 ms 1.057 ms -2.0%
game-sm-success_2-6 419.0 μs 410.9 μs -1.9%
multisig-sm-1 706.1 μs 696.4 μs -1.4%
multisig-sm-2 690.0 μs 682.6 μs -1.1%
multisig-sm-3 697.2 μs 688.5 μs -1.2%
multisig-sm-4 706.0 μs 695.8 μs -1.4%
multisig-sm-5 955.7 μs 938.8 μs -1.8%
multisig-sm-6 705.4 μs 694.6 μs -1.5%
multisig-sm-7 691.2 μs 681.2 μs -1.4%
multisig-sm-8 698.3 μs 688.0 μs -1.5%
multisig-sm-9 707.3 μs 696.5 μs -1.5%
multisig-sm-10 952.9 μs 937.4 μs -1.6%
ping-pong-1 577.2 μs 568.6 μs -1.5%
ping-pong-2 575.8 μs 570.5 μs -0.9%
ping-pong_2-1 355.9 μs 351.8 μs -1.2%
prism-1 298.0 μs 291.1 μs -2.3%
prism-2 757.5 μs 746.1 μs -1.5%
prism-3 642.4 μs 628.5 μs -2.2%
pubkey-1 254.8 μs 250.0 μs -1.9%
stablecoin_1-1 1.493 ms 1.461 ms -2.1%
stablecoin_1-2 351.0 μs 343.2 μs -2.2%
stablecoin_1-3 1.695 ms 1.660 ms -2.1%
stablecoin_1-4 370.4 μs 363.0 μs -2.0%
stablecoin_1-5 2.137 ms 2.092 ms -2.1%
stablecoin_1-6 461.2 μs 453.4 μs -1.7%
stablecoin_2-1 1.479 ms 1.464 ms -1.0%
stablecoin_2-2 349.2 μs 343.6 μs -1.6%
stablecoin_2-3 1.689 ms 1.663 ms -1.5%
stablecoin_2-4 371.8 μs 363.3 μs -2.3%
token-account-1 322.5 μs 315.4 μs -2.2%
token-account-2 573.8 μs 559.7 μs -2.5%
uniswap-1 677.5 μs 666.1 μs -1.7%
uniswap-2 387.6 μs 382.1 μs -1.4%
uniswap-3 2.708 ms 2.679 ms -1.1%
uniswap-4 609.9 μs 601.9 μs -1.3%
uniswap-5 1.917 ms 1.888 ms -1.5%
uniswap-6 582.3 μs 572.5 μs -1.7%
vesting-1 600.3 μs 586.0 μs -2.4%

@effectfully effectfully force-pushed the effectfully/builtins/inline-KnownBuiltinTypeIn-constraints branch from 5581c30 to 2fa61f9 Compare February 12, 2022 14:31
@effectfully
Copy link
Contributor Author

Ready for review.

@effectfully effectfully requested review from kwxm and michaelpj and removed request for kwxm February 12, 2022 14:32
@effectfully
Copy link
Contributor Author

Wait, what.

@effectfully
Copy link
Contributor Author

Screenshot from 2022-02-12 17-32-45

@effectfully
Copy link
Contributor Author

Seems like a glitch to me. Removing some constraints hardly can make the code slower. Core is much better. Everything else got a speedup.

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on 'afe6dcd54' (base) and 'f9ccac2e7' (PR)

Script afe6dcd f9ccac2 Change
auction_1-1 296.9 μs 297.0 μs +0.0%
auction_1-2 965.4 μs 967.7 μs +0.2%
auction_1-3 962.3 μs 965.7 μs +0.4%
auction_1-4 389.3 μs 392.7 μs +0.9%
auction_2-1 296.7 μs 300.3 μs +1.2%
auction_2-2 968.6 μs 967.4 μs -0.1%
auction_2-3 1.231 ms 1.215 ms -1.3%
auction_2-4 968.3 μs 964.3 μs -0.4%
auction_2-5 390.3 μs 392.6 μs +0.6%
crowdfunding-success-1 351.4 μs 350.9 μs -0.1%
crowdfunding-success-2 350.4 μs 350.5 μs +0.0%
crowdfunding-success-3 350.2 μs 350.3 μs +0.0%
currency-1 380.1 μs 380.9 μs +0.2%
escrow-redeem_1-1 557.4 μs 558.7 μs +0.2%
escrow-redeem_1-2 557.6 μs 560.1 μs +0.4%
escrow-redeem_2-1 649.1 μs 653.8 μs +0.7%
escrow-redeem_2-2 650.8 μs 653.1 μs +0.4%
escrow-redeem_2-3 653.0 μs 652.8 μs -0.0%
escrow-refund-1 260.5 μs 259.6 μs -0.3%
future-increase-margin-1 380.4 μs 381.3 μs +0.2%
future-increase-margin-2 843.1 μs 845.9 μs +0.3%
future-increase-margin-3 847.8 μs 848.5 μs +0.1%
future-increase-margin-4 776.7 μs 774.0 μs -0.3%
future-increase-margin-5 1.177 ms 1.173 ms -0.3%
future-pay-out-1 381.5 μs 382.7 μs +0.3%
future-pay-out-2 846.3 μs 845.9 μs -0.0%
future-pay-out-3 844.5 μs 844.3 μs -0.0%
future-pay-out-4 1.167 ms 1.168 ms +0.1%
future-settle-early-1 379.8 μs 380.6 μs +0.2%
future-settle-early-2 845.1 μs 842.7 μs -0.3%
future-settle-early-3 843.2 μs 846.1 μs +0.3%
future-settle-early-4 904.2 μs 907.8 μs +0.4%
game-sm-success_1-1 624.7 μs 620.7 μs -0.6%
game-sm-success_1-2 330.9 μs 331.5 μs +0.2%
game-sm-success_1-3 970.6 μs 964.5 μs -0.6%
game-sm-success_1-4 386.0 μs 386.6 μs +0.2%
game-sm-success_2-1 621.9 μs 621.9 μs 0.0%
game-sm-success_2-2 331.0 μs 333.2 μs +0.7%
game-sm-success_2-3 972.4 μs 971.2 μs -0.1%
game-sm-success_2-4 386.9 μs 387.4 μs +0.1%
game-sm-success_2-5 974.3 μs 968.1 μs -0.6%
game-sm-success_2-6 385.4 μs 386.6 μs +0.3%
multisig-sm-1 627.9 μs 625.0 μs -0.5%
multisig-sm-2 613.6 μs 612.7 μs -0.1%
multisig-sm-3 619.4 μs 620.5 μs +0.2%
multisig-sm-4 628.3 μs 625.5 μs -0.4%
multisig-sm-5 850.2 μs 853.4 μs +0.4%
multisig-sm-6 627.9 μs 625.4 μs -0.4%
multisig-sm-7 614.1 μs 613.5 μs -0.1%
multisig-sm-8 621.4 μs 620.0 μs -0.2%
multisig-sm-9 628.7 μs 625.5 μs -0.5%
multisig-sm-10 851.0 μs 851.3 μs +0.0%
ping-pong-1 521.4 μs 518.7 μs -0.5%
ping-pong-2 521.0 μs 518.7 μs -0.4%
ping-pong_2-1 322.7 μs 323.6 μs +0.3%
prism-1 275.7 μs 274.8 μs -0.3%
prism-2 675.0 μs 667.9 μs -1.1%
prism-3 581.6 μs 580.9 μs -0.1%
pubkey-1 234.5 μs 236.2 μs +0.7%
stablecoin_1-1 1.368 ms 1.345 ms -1.7%
stablecoin_1-2 322.6 μs 324.0 μs +0.4%
stablecoin_1-3 1.575 ms 1.534 ms -2.6%
stablecoin_1-4 342.5 μs 344.3 μs +0.5%
stablecoin_1-5 2.007 ms 1.964 ms -2.1%
stablecoin_1-6 424.1 μs 427.2 μs +0.7%
stablecoin_2-1 1.368 ms 1.343 ms -1.8%
stablecoin_2-2 320.8 μs 323.2 μs +0.7%
stablecoin_2-3 1.571 ms 1.538 ms -2.1%
stablecoin_2-4 343.3 μs 345.1 μs +0.5%
token-account-1 296.2 μs 298.5 μs +0.8%
token-account-2 516.2 μs 520.1 μs +0.8%
uniswap-1 609.6 μs 612.1 μs +0.4%
uniswap-2 355.6 μs 358.8 μs +0.9%
uniswap-3 2.579 ms 2.526 ms -2.1%
uniswap-4 566.3 μs 566.8 μs +0.1%
uniswap-5 1.818 ms 1.777 ms -2.3%
uniswap-6 541.5 μs 540.7 μs -0.1%
vesting-1 537.0 μs 536.2 μs -0.1%

@effectfully
Copy link
Contributor Author

Oops, merged instead of rebasing, fixing.

@effectfully effectfully force-pushed the effectfully/builtins/inline-KnownBuiltinTypeIn-constraints branch 2 times, most recently from f2c666f to 03a216e Compare February 13, 2022 02:38
@effectfully
Copy link
Contributor Author

@michaelpj what's wrong with CI?

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:validation

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:validation' on 'afe6dcd54' (base) and '03a216ed0' (PR)

Script afe6dcd 03a216e Change
auction_1-1 298.1 μs 296.3 μs -0.6%
auction_1-2 967.8 μs 958.9 μs -0.9%
auction_1-3 966.0 μs 959.2 μs -0.7%
auction_1-4 390.9 μs 390.7 μs -0.1%
auction_2-1 299.3 μs 298.3 μs -0.3%
auction_2-2 964.7 μs 965.0 μs +0.0%
auction_2-3 1.226 ms 1.216 ms -0.8%
auction_2-4 961.6 μs 963.2 μs +0.2%
auction_2-5 389.8 μs 390.8 μs +0.3%
crowdfunding-success-1 351.7 μs 351.2 μs -0.1%
crowdfunding-success-2 352.2 μs 348.5 μs -1.1%
crowdfunding-success-3 351.4 μs 348.8 μs -0.7%
currency-1 379.5 μs 380.8 μs +0.3%
escrow-redeem_1-1 560.3 μs 556.9 μs -0.6%
escrow-redeem_1-2 559.2 μs 556.7 μs -0.4%
escrow-redeem_2-1 653.8 μs 650.5 μs -0.5%
escrow-redeem_2-2 654.8 μs 648.8 μs -0.9%
escrow-redeem_2-3 655.1 μs 651.3 μs -0.6%
escrow-refund-1 261.7 μs 259.3 μs -0.9%
future-increase-margin-1 380.7 μs 380.2 μs -0.1%
future-increase-margin-2 846.4 μs 839.6 μs -0.8%
future-increase-margin-3 845.8 μs 840.6 μs -0.6%
future-increase-margin-4 771.2 μs 770.7 μs -0.1%
future-increase-margin-5 1.170 ms 1.170 ms 0.0%
future-pay-out-1 381.0 μs 382.4 μs +0.4%
future-pay-out-2 846.9 μs 849.0 μs +0.2%
future-pay-out-3 847.8 μs 844.7 μs -0.4%
future-pay-out-4 1.168 ms 1.169 ms +0.1%
future-settle-early-1 380.3 μs 380.8 μs +0.1%
future-settle-early-2 846.9 μs 843.8 μs -0.4%
future-settle-early-3 849.5 μs 841.0 μs -1.0%
future-settle-early-4 913.9 μs 905.3 μs -0.9%
game-sm-success_1-1 626.3 μs 619.4 μs -1.1%
game-sm-success_1-2 332.5 μs 329.6 μs -0.9%
game-sm-success_1-3 973.9 μs 964.2 μs -1.0%
game-sm-success_1-4 386.7 μs 386.3 μs -0.1%
game-sm-success_2-1 624.3 μs 620.1 μs -0.7%
game-sm-success_2-2 331.3 μs 330.2 μs -0.3%
game-sm-success_2-3 970.1 μs 963.7 μs -0.7%
game-sm-success_2-4 387.1 μs 384.6 μs -0.6%
game-sm-success_2-5 973.3 μs 969.6 μs -0.4%
game-sm-success_2-6 386.0 μs 387.3 μs +0.3%
multisig-sm-1 627.7 μs 626.0 μs -0.3%
multisig-sm-2 613.7 μs 615.0 μs +0.2%
multisig-sm-3 623.4 μs 620.9 μs -0.4%
multisig-sm-4 633.2 μs 625.7 μs -1.2%
multisig-sm-5 859.3 μs 851.5 μs -0.9%
multisig-sm-6 630.2 μs 624.1 μs -1.0%
multisig-sm-7 617.9 μs 611.9 μs -1.0%
multisig-sm-8 624.5 μs 616.5 μs -1.3%
multisig-sm-9 631.3 μs 624.1 μs -1.1%
multisig-sm-10 856.9 μs 850.5 μs -0.7%
ping-pong-1 520.8 μs 517.2 μs -0.7%
ping-pong-2 519.5 μs 516.2 μs -0.6%
ping-pong_2-1 322.1 μs 321.6 μs -0.2%
prism-1 275.5 μs 273.9 μs -0.6%
prism-2 674.6 μs 667.1 μs -1.1%
prism-3 583.1 μs 580.5 μs -0.4%
pubkey-1 234.8 μs 235.6 μs +0.3%
stablecoin_1-1 1.370 ms 1.347 ms -1.7%
stablecoin_1-2 322.7 μs 323.3 μs +0.2%
stablecoin_1-3 1.579 ms 1.545 ms -2.2%
stablecoin_1-4 343.5 μs 343.9 μs +0.1%
stablecoin_1-5 2.016 ms 1.963 ms -2.6%
stablecoin_1-6 427.4 μs 425.7 μs -0.4%
stablecoin_2-1 1.376 ms 1.343 ms -2.4%
stablecoin_2-2 324.3 μs 321.7 μs -0.8%
stablecoin_2-3 1.584 ms 1.536 ms -3.0%
stablecoin_2-4 346.2 μs 342.4 μs -1.1%
token-account-1 297.0 μs 295.2 μs -0.6%
token-account-2 518.9 μs 515.4 μs -0.7%
uniswap-1 614.1 μs 609.3 μs -0.8%
uniswap-2 357.7 μs 356.7 μs -0.3%
uniswap-3 2.593 ms 2.523 ms -2.7%
uniswap-4 568.3 μs 565.3 μs -0.5%
uniswap-5 1.816 ms 1.775 ms -2.3%
uniswap-6 540.1 μs 542.6 μs +0.5%
vesting-1 536.7 μs 538.0 μs +0.2%

@effectfully effectfully force-pushed the effectfully/builtins/inline-KnownBuiltinTypeIn-constraints branch from 03a216e to fe3ee8c Compare February 13, 2022 14:23
@effectfully
Copy link
Contributor Author

effectfully commented Feb 13, 2022

I don't know why benchmarks are being

image

after I rebased on master, but it's still a speedup (albeit a tiny one) and the generated Core is definitely better, so I believe it's still worth merging.

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.

I guess if you think the Core is clearly better I'm okay with it, but I think the speedup is below our noise threshold so 🤷

@bezirg
Copy link
Contributor

bezirg commented Feb 14, 2022

The escrow ones got slower after the skew binary change. These are the only 3 that are underperforming when using skewbinary instead of intmap as the env. I have not investigated why.

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:nofib

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:nofib' on 'afe6dcd54' (base) and 'fe3ee8c70' (PR)

Script afe6dcd fe3ee8c Change
clausify/formula1 23.18 ms 23.44 ms +1.1%
clausify/formula2 28.60 ms 28.94 ms +1.2%
clausify/formula3 78.10 ms 78.94 ms +1.1%
clausify/formula4 133.5 ms 135.0 ms +1.1%
clausify/formula5 496.4 ms 501.0 ms +0.9%
knights/4x4 72.99 ms 72.37 ms -0.8%
knights/6x6 193.3 ms 192.9 ms -0.2%
knights/8x8 319.7 ms 318.9 ms -0.3%
primetest/05digits 52.26 ms 51.32 ms -1.8%
primetest/08digits 97.17 ms 94.80 ms -2.4%
primetest/10digits 137.6 ms 134.0 ms -2.6%
primetest/20digits 274.5 ms 269.4 ms -1.9%
primetest/30digits 397.5 ms 391.1 ms -1.6%
primetest/40digits 533.7 ms 525.9 ms -1.5%
primetest/50digits 531.2 ms 520.0 ms -2.1%
queens4x4/bt 11.84 ms 11.93 ms +0.8%
queens4x4/bm 16.84 ms 16.91 ms +0.4%
queens4x4/bjbt1 14.64 ms 14.74 ms +0.7%
queens4x4/bjbt2 15.61 ms 15.73 ms +0.8%
queens4x4/fc 36.51 ms 36.70 ms +0.5%
queens5x5/bt 160.6 ms 161.0 ms +0.2%
queens5x5/bm 195.3 ms 196.8 ms +0.8%
queens5x5/bjbt1 189.1 ms 190.1 ms +0.5%
queens5x5/bjbt2 199.0 ms 200.3 ms +0.7%
queens5x5/fc 464.1 ms 468.3 ms +0.9%

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:nofib

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:nofib' on 'afe6dcd54' (base) and 'fe3ee8c70' (PR)

Script afe6dcd fe3ee8c Change
clausify/formula1 23.22 ms 23.40 ms +0.8%
clausify/formula2 28.68 ms 29.02 ms +1.2%
clausify/formula3 78.23 ms 78.96 ms +0.9%
clausify/formula4 133.4 ms 135.2 ms +1.3%
clausify/formula5 496.5 ms 500.9 ms +0.9%
knights/4x4 72.72 ms 72.58 ms -0.2%
knights/6x6 193.3 ms 193.0 ms -0.2%
knights/8x8 319.4 ms 318.8 ms -0.2%
primetest/05digits 52.42 ms 51.13 ms -2.5%
primetest/08digits 97.09 ms 95.01 ms -2.1%
primetest/10digits 137.7 ms 133.5 ms -3.1%
primetest/20digits 273.9 ms 268.5 ms -2.0%
primetest/30digits 399.3 ms 389.9 ms -2.4%
primetest/40digits 533.5 ms 522.4 ms -2.1%
primetest/50digits 530.5 ms 516.8 ms -2.6%
queens4x4/bt 11.87 ms 11.92 ms +0.4%
queens4x4/bm 16.83 ms 16.92 ms +0.5%
queens4x4/bjbt1 14.62 ms 14.76 ms +1.0%
queens4x4/bjbt2 15.57 ms 15.70 ms +0.8%
queens4x4/fc 36.54 ms 36.79 ms +0.7%
queens5x5/bt 160.4 ms 161.0 ms +0.4%
queens5x5/bm 195.1 ms 196.4 ms +0.7%
queens5x5/bjbt1 188.8 ms 190.1 ms +0.7%
queens5x5/bjbt2 199.6 ms 200.3 ms +0.4%
queens5x5/fc 465.5 ms 468.6 ms +0.7%

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:nofib

@iohk-devops
Copy link

Comparing benchmark results of 'plutus-benchmark:nofib' on 'afe6dcd54' (base) and 'fe3ee8c70' (PR)

Script afe6dcd fe3ee8c Change
clausify/formula1 23.23 ms 23.42 ms +0.8%
clausify/formula2 28.75 ms 28.95 ms +0.7%
clausify/formula3 78.18 ms 79.03 ms +1.1%
clausify/formula4 134.1 ms 134.6 ms +0.4%
clausify/formula5 497.8 ms 501.8 ms +0.8%
knights/4x4 72.91 ms 72.41 ms -0.7%
knights/6x6 193.8 ms 193.0 ms -0.4%
knights/8x8 320.3 ms 318.8 ms -0.5%
primetest/05digits 52.40 ms 51.23 ms -2.2%
primetest/08digits 97.06 ms 94.87 ms -2.3%
primetest/10digits 137.2 ms 135.2 ms -1.5%
primetest/20digits 275.5 ms 268.6 ms -2.5%
primetest/30digits 398.6 ms 389.5 ms -2.3%
primetest/40digits 534.5 ms 524.6 ms -1.9%
primetest/50digits 531.0 ms 517.6 ms -2.5%
queens4x4/bt 11.86 ms 11.91 ms +0.4%
queens4x4/bm 16.83 ms 16.90 ms +0.4%
queens4x4/bjbt1 14.66 ms 14.78 ms +0.8%
queens4x4/bjbt2 15.62 ms 15.72 ms +0.6%
queens4x4/fc 36.48 ms 36.72 ms +0.7%
queens5x5/bt 160.3 ms 161.3 ms +0.6%
queens5x5/bm 195.2 ms 196.2 ms +0.5%
queens5x5/bjbt1 188.8 ms 190.3 ms +0.8%
queens5x5/bjbt2 199.1 ms 200.6 ms +0.8%
queens5x5/fc 466.2 ms 469.1 ms +0.6%

@effectfully
Copy link
Contributor Author

I guess if you think the Core is clearly better I'm okay with it, but I think the speedup is below our noise threshold so shrug

I think a 2% change is above our noise threshold. In any case, this PR is essential. Here's how readKnown used to compile:

-- RHS size: {terms: 76, types: 249, coercions: 41, joins: 0/0}
$fKnownTypeInDefaultUnitermInteger_$creadKnown
  = \ @ term_ag9l $d(%,,,%)_ag9m @ cause_ag9N eta_B2 eta1_B1 ->
      case eq_sel ($p1(%,%) ($p1(%,,,%) $d(%,,,%)_ag9m)) of co_agQ7
      { __DEFAULT ->
      case $d(%,,,%)_ag9m of
      { (ww1_sFbW, ww2_sFc6, ww3_sFc7, ww4_sFc8) ->
      case ww1_sFbW of { (ww6_sFbZ, ww7_sFc4) ->
      case ww6_sFbZ of { Eq# ww9_sFc2 ->
      case (($p1(%,%) ww7_sFc4) `cast` <Co:2>)
             $fAsUnliftingErrorReadKnownError eta_B2 eta1_B1
      of {
        Left l_iv28 -> Left l_iv28;
        Right r_iv2a ->
          case r_iv2a `cast` <Co:5> of { ValueOf uniAct_iv2d x_iv2e ->
          case (ww3_sFc7 `cast` <Co:4>) uniAct_iv2d (ww4_sFc8 `cast` <Co:6>)
          of {
            Nothing ->
              Left <...>
            Just ds_iv2l ->
              case ds_iv2l of { Refl co1_iv2o -> (Right x_iv2e) `cast` <Co:8> }
          }
          }
      }
      }
      }
      }
      }

Here's how it compiles now:

-- RHS size: {terms: 61, types: 182, coercions: 37, joins: 0/0}
$fKnownTypeInDefaultUnitermInteger_$creadKnown
  = \ @ term_a2ffv $d(%,%)_a2ffw @ cause_a2ffX eta_B2 eta1_B1 ->
      case eq_sel ($p1(%,%) $d(%,%)_a2ffw) of co_a2fBV { __DEFAULT ->
      case $p1(%,%) $d(%,%)_a2ffw of { Eq# ww1_s2DsX ->
      case (($p1(%,%) ($p2(%,%) ($d(%,%)_a2ffw `cast` <Co:15>)))
            `cast` <Co:2>)
             $fAsUnliftingErrorReadKnownError eta_B2 eta1_B1
      of {
        Left l_i1W2s -> Left l_i1W2s;
        Right r_i1W2u ->
          case r_i1W2u `cast` <Co:5> of { ValueOf uniAct_a1UPO x_a1UPP ->
          case uniAct_a1UPO `cast` <Co:6> of wild2_XR {
            __DEFAULT ->
              Left <...>
            DefaultUniInteger co1_a2eQY -> (Right x_a1UPP) `cast` <Co:7>
          }
          }
      }
      }
      }

Note how in the latter we directly match on DefaultUniInteger instead of checking two things for equality at runtime and manually extracting the proof.

I'm not sure where the occasional slowdown is coming from (I did look at the whole Core output closely), maybe those $p1(%,%) and $p2(%,%) are slow and we have more of them now, but I think the changes are worth merging and I have a branch where all of HasConstant stuff is inlined and we don't have as many selectors there.

Co-authored-by: Michael Peyton Jones <michael.peyton-jones@iohk.io>
@effectfully effectfully merged commit 0397f83 into master Feb 18, 2022
@effectfully effectfully deleted the effectfully/builtins/inline-KnownBuiltinTypeIn-constraints branch February 18, 2022 23:47
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.

4 participants