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

[Evaluation] Statically unroll 'itraverseCounter_' #5265

Conversation

effectfully
Copy link
Contributor

Results in a statically unrolled loop:

    let! { (# ipv10_X1x, ipv11_X1y #) ~ <- $wf_svLt 0# (ipv8_itGb `cast` <Co:8>) } in
    let! { (# ipv12_X1B, ipv13_X1C #) ~ <- $wf_svLt 1# ipv10_X1x } in
    let! { (# ipv14_X1F, ipv15_X1G #) ~ <- $wf_svLt 2# ipv12_X1B } in
    let! { (# ipv16_X1U, ipv17_X1V #) ~ <- $wf_svLt 3# ipv14_X1F } in
    let! { (# ipv18_X1X, ipv19_X1Y #) ~ <- $wf_svLt 4# ipv16_X1U } in
    let! { (# ipv20_X20, ipv21_X21 #) ~ <- $wf_svLt 5# ipv18_X1X } in
    let! { (# ipv22_X23, ipv23_X24 #) ~ <- $wf_svLt 6# ipv20_X20 } in
    let! { (# ipv24_X29, ipv25_X2a #) ~ <- $wf_svLt 7# ipv22_X23 } in
    let! { (# ipv26_X2f, ipv27_X2g #) ~ <- $wf_svLt 8# ipv24_X29 } in
    let! { (# ipv28_X2l, ipv29_X2m #) ~ <- $wf_svLt 9# ipv26_X2f } in
    let! { UnsafeRefl v4_itGA ~ <- unsafeEqualityProof } in
    let! { UnsafeRefl v5_itGz ~ <- unsafeEqualityProof } in
    let! { __DEFAULT ~ wild19_itGD
    <- setByteArray#
         (ipv5_itD3 `cast` <Co:11>)
         0#
         10#
         0#
         (ipv28_X2l `cast` <Co:10>) } in
    let! { UnsafeRefl v6_itGF ~ <- unsafeEqualityProof } in
    (# wild19_itGD, () #) `cast` <Co:15> } in

Not sure if it's worth it though, let's ask benchmarks.

@effectfully effectfully added Evaluation Performance No Changelog Required Add this to skip the Changelog Check labels Apr 19, 2023
@effectfully
Copy link
Contributor Author

/benchmark validation

@github-actions
Copy link
Contributor

Click here to check the status of your benchmark.

@effectfully
Copy link
Contributor Author

/benchmark validation

@github-actions
Copy link
Contributor

Click here to check the status of your benchmark.

@effectfully
Copy link
Contributor Author

/benchmark validation

@github-actions
Copy link
Contributor

Comparing benchmark results of ' validation' on '48a20b623' (base) and '50b077a0c' (PR)

Results table
Script 48a20b6 50b077a Change
auction_1-1 180.5 μs 176.4 μs -2.3%
auction_1-2 737.6 μs 731.2 μs -0.9%
auction_1-3 728.4 μs 719.0 μs -1.3%
auction_1-4 232.3 μs 230.0 μs -1.0%
auction_2-1 182.1 μs 179.4 μs -1.5%
auction_2-2 739.9 μs 735.9 μs -0.5%
auction_2-3 971.2 μs 958.9 μs -1.3%
auction_2-4 727.1 μs 723.1 μs -0.6%
auction_2-5 232.1 μs 230.7 μs -0.6%
crowdfunding-success-1 214.6 μs 211.0 μs -1.7%
crowdfunding-success-2 214.8 μs 211.3 μs -1.6%
crowdfunding-success-3 214.6 μs 211.6 μs -1.4%
currency-1 272.8 μs 268.1 μs -1.7%
escrow-redeem_1-1 377.6 μs 378.4 μs +0.2%
escrow-redeem_1-2 378.7 μs 380.9 μs +0.6%
escrow-redeem_2-1 440.3 μs 440.3 μs 0.0%
escrow-redeem_2-2 442.1 μs 438.5 μs -0.8%
escrow-redeem_2-3 439.3 μs 437.9 μs -0.3%
escrow-refund-1 157.3 μs 156.8 μs -0.3%
future-increase-margin-1 272.3 μs 268.4 μs -1.4%
future-increase-margin-2 594.7 μs 588.8 μs -1.0%
future-increase-margin-3 596.4 μs 593.3 μs -0.5%
future-increase-margin-4 552.6 μs 551.7 μs -0.2%
future-increase-margin-5 941.7 μs 931.7 μs -1.1%
future-pay-out-1 273.0 μs 267.7 μs -1.9%
future-pay-out-2 593.1 μs 589.6 μs -0.6%
future-pay-out-3 597.2 μs 591.1 μs -1.0%
future-pay-out-4 940.7 μs 933.4 μs -0.8%
future-settle-early-1 272.8 μs 268.0 μs -1.8%
future-settle-early-2 595.1 μs 590.7 μs -0.7%
future-settle-early-3 597.0 μs 593.6 μs -0.6%
future-settle-early-4 696.9 μs 693.2 μs -0.5%
game-sm-success_1-1 432.8 μs 425.6 μs -1.7%
game-sm-success_1-2 199.4 μs 198.6 μs -0.4%
game-sm-success_1-3 732.1 μs 716.7 μs -2.1%
game-sm-success_1-4 233.2 μs 232.3 μs -0.4%
game-sm-success_2-1 430.1 μs 423.5 μs -1.5%
game-sm-success_2-2 199.2 μs 198.6 μs -0.3%
game-sm-success_2-3 730.3 μs 714.6 μs -2.1%
game-sm-success_2-4 233.6 μs 232.7 μs -0.4%
game-sm-success_2-5 726.8 μs 710.8 μs -2.2%
game-sm-success_2-6 233.3 μs 232.0 μs -0.6%
multisig-sm-1 444.1 μs 434.3 μs -2.2%
multisig-sm-2 433.4 μs 425.3 μs -1.9%
multisig-sm-3 439.0 μs 429.9 μs -2.1%
multisig-sm-4 444.0 μs 439.8 μs -0.9%
multisig-sm-5 640.4 μs 627.3 μs -2.0%
multisig-sm-6 444.6 μs 436.7 μs -1.8%
multisig-sm-7 433.9 μs 424.7 μs -2.1%
multisig-sm-8 436.4 μs 431.6 μs -1.1%
multisig-sm-9 443.8 μs 439.9 μs -0.9%
multisig-sm-10 637.9 μs 626.1 μs -1.8%
ping-pong-1 367.2 μs 358.2 μs -2.5%
ping-pong-2 367.6 μs 359.2 μs -2.3%
ping-pong_2-1 212.1 μs 209.7 μs -1.1%
prism-1 166.9 μs 167.0 μs +0.1%
prism-2 454.1 μs 453.1 μs -0.2%
prism-3 394.8 μs 394.7 μs -0.0%
pubkey-1 142.3 μs 141.4 μs -0.6%
stablecoin_1-1 1.036 ms 1.025 ms -1.1%
stablecoin_1-2 194.9 μs 193.4 μs -0.8%
stablecoin_1-3 1.197 ms 1.177 ms -1.7%
stablecoin_1-4 206.5 μs 206.0 μs -0.2%
stablecoin_1-5 1.530 ms 1.499 ms -2.0%
stablecoin_1-6 256.8 μs 254.4 μs -0.9%
stablecoin_2-1 1.038 ms 1.025 ms -1.3%
stablecoin_2-2 195.6 μs 193.0 μs -1.3%
stablecoin_2-3 1.201 ms 1.176 ms -2.1%
stablecoin_2-4 207.7 μs 206.3 μs -0.7%
token-account-1 201.1 μs 199.2 μs -0.9%
token-account-2 363.8 μs 361.8 μs -0.5%
uniswap-1 457.9 μs 458.4 μs +0.1%
uniswap-2 235.3 μs 229.6 μs -2.4%
uniswap-3 2.009 ms 1.983 ms -1.3%
uniswap-4 337.5 μs 331.8 μs -1.7%
uniswap-5 1.289 ms 1.272 ms -1.3%
uniswap-6 323.6 μs 320.0 μs -1.1%
vesting-1 394.6 μs 384.3 μs -2.6%

@github-actions
Copy link
Contributor

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

Comparing benchmark results of ' validation' on '48a20b623' (base) and '50b077a0c' (PR)

Results table
Script 48a20b6 50b077a Change
auction_1-1 179.6 μs 176.7 μs -1.6%
auction_1-2 731.6 μs 733.4 μs +0.2%
auction_1-3 722.0 μs 723.6 μs +0.2%
auction_1-4 230.6 μs 231.0 μs +0.2%
auction_2-1 181.6 μs 179.1 μs -1.4%
auction_2-2 730.7 μs 733.6 μs +0.4%
auction_2-3 962.9 μs 958.5 μs -0.5%
auction_2-4 719.7 μs 725.7 μs +0.8%
auction_2-5 231.0 μs 231.5 μs +0.2%
crowdfunding-success-1 213.3 μs 211.5 μs -0.8%
crowdfunding-success-2 213.5 μs 211.2 μs -1.1%
crowdfunding-success-3 213.6 μs 211.1 μs -1.2%
currency-1 271.6 μs 268.0 μs -1.3%
escrow-redeem_1-1 375.5 μs 378.4 μs +0.8%
escrow-redeem_1-2 378.2 μs 379.9 μs +0.4%
escrow-redeem_2-1 439.6 μs 439.7 μs +0.0%
escrow-redeem_2-2 440.0 μs 437.2 μs -0.6%
escrow-redeem_2-3 440.1 μs 436.8 μs -0.7%
escrow-refund-1 157.0 μs 156.0 μs -0.6%
future-increase-margin-1 271.3 μs 267.8 μs -1.3%
future-increase-margin-2 589.4 μs 588.1 μs -0.2%
future-increase-margin-3 598.2 μs 592.4 μs -1.0%
future-increase-margin-4 554.5 μs 547.7 μs -1.2%
future-increase-margin-5 951.0 μs 937.9 μs -1.4%
future-pay-out-1 273.4 μs 268.3 μs -1.9%
future-pay-out-2 596.1 μs 589.1 μs -1.2%
future-pay-out-3 599.1 μs 592.3 μs -1.1%
future-pay-out-4 945.4 μs 933.1 μs -1.3%
future-settle-early-1 273.7 μs 268.5 μs -1.9%
future-settle-early-2 595.7 μs 590.6 μs -0.9%
future-settle-early-3 598.4 μs 593.3 μs -0.9%
future-settle-early-4 699.4 μs 695.5 μs -0.6%
game-sm-success_1-1 435.1 μs 426.7 μs -1.9%
game-sm-success_1-2 199.8 μs 198.3 μs -0.8%
game-sm-success_1-3 734.8 μs 715.7 μs -2.6%
game-sm-success_1-4 234.9 μs 232.1 μs -1.2%
game-sm-success_2-1 432.4 μs 422.7 μs -2.2%
game-sm-success_2-2 199.9 μs 198.3 μs -0.8%
game-sm-success_2-3 734.4 μs 715.6 μs -2.6%
game-sm-success_2-4 234.6 μs 232.8 μs -0.8%
game-sm-success_2-5 734.1 μs 717.3 μs -2.3%
game-sm-success_2-6 234.1 μs 233.1 μs -0.4%
multisig-sm-1 447.1 μs 436.7 μs -2.3%
multisig-sm-2 436.3 μs 426.0 μs -2.4%
multisig-sm-3 441.7 μs 430.8 μs -2.5%
multisig-sm-4 446.3 μs 441.5 μs -1.1%
multisig-sm-5 637.5 μs 628.0 μs -1.5%
multisig-sm-6 443.2 μs 435.5 μs -1.7%
multisig-sm-7 436.4 μs 425.2 μs -2.6%
multisig-sm-8 441.8 μs 430.2 μs -2.6%
multisig-sm-9 447.0 μs 440.0 μs -1.6%
multisig-sm-10 642.3 μs 627.4 μs -2.3%
ping-pong-1 370.7 μs 359.2 μs -3.1%
ping-pong-2 370.9 μs 359.4 μs -3.1%
ping-pong_2-1 212.3 μs 209.9 μs -1.1%
prism-1 166.9 μs 167.2 μs +0.2%
prism-2 453.8 μs 453.3 μs -0.1%
prism-3 395.0 μs 393.7 μs -0.3%
pubkey-1 141.9 μs 141.8 μs -0.1%
stablecoin_1-1 1.037 ms 1.024 ms -1.3%
stablecoin_1-2 195.3 μs 193.5 μs -0.9%
stablecoin_1-3 1.194 ms 1.177 ms -1.4%
stablecoin_1-4 207.6 μs 206.5 μs -0.5%
stablecoin_1-5 1.527 ms 1.498 ms -1.9%
stablecoin_1-6 256.6 μs 254.5 μs -0.8%
stablecoin_2-1 1.035 ms 1.026 ms -0.9%
stablecoin_2-2 195.1 μs 192.4 μs -1.4%
stablecoin_2-3 1.193 ms 1.167 ms -2.2%
stablecoin_2-4 207.3 μs 205.2 μs -1.0%
token-account-1 201.0 μs 198.2 μs -1.4%
token-account-2 362.6 μs 361.7 μs -0.2%
uniswap-1 456.1 μs 457.7 μs +0.4%
uniswap-2 234.5 μs 229.6 μs -2.1%
uniswap-3 2.003 ms 1.984 ms -0.9%
uniswap-4 335.7 μs 332.5 μs -1.0%
uniswap-5 1.285 ms 1.270 ms -1.2%
uniswap-6 322.4 μs 319.7 μs -0.8%
vesting-1 394.0 μs 383.6 μs -2.6%

@effectfully
Copy link
Contributor Author

The first run is -1.13% on average, then second one is -1.12%.

Looks like a modest improvement, but really hard to tell with the benchmarks not being reliable for such little things at all.

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:nofib

@github-actions
Copy link
Contributor

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

Comparing benchmark results of ' plutus-benchmark:nofib' on '48a20b623' (base) and '50b077a0c' (PR)

Results table
Script 48a20b6 50b077a Change
clausify/formula1 15.47 ms 15.62 ms +1.0%
clausify/formula2 19.81 ms 20.15 ms +1.7%
clausify/formula3 54.56 ms 55.15 ms +1.1%
clausify/formula4 82.97 ms 84.22 ms +1.5%
clausify/formula5 338.9 ms 341.0 ms +0.6%
knights/4x4 59.81 ms 59.75 ms -0.1%
knights/6x6 156.7 ms 159.8 ms +2.0%
knights/8x8 257.1 ms 263.0 ms +2.3%
primetest/05digits 28.37 ms 28.38 ms +0.0%
primetest/08digits 51.26 ms 51.64 ms +0.7%
primetest/10digits 71.39 ms 71.99 ms +0.8%
primetest/20digits 148.7 ms 150.3 ms +1.1%
primetest/30digits 218.7 ms 221.2 ms +1.1%
primetest/40digits 300.9 ms 305.3 ms +1.5%
primetest/50digits 287.0 ms 291.4 ms +1.5%
queens4x4/bt 10.67 ms 10.78 ms +1.0%
queens4x4/bm 15.09 ms 15.02 ms -0.5%
queens4x4/bjbt1 13.17 ms 13.27 ms +0.8%
queens4x4/bjbt2 13.36 ms 13.50 ms +1.0%
queens4x4/fc 28.17 ms 28.17 ms 0.0%
queens5x5/bt 138.6 ms 139.7 ms +0.8%
queens5x5/bm 172.1 ms 172.6 ms +0.3%
queens5x5/bjbt1 164.3 ms 166.4 ms +1.3%
queens5x5/bjbt2 168.9 ms 171.1 ms +1.3%
queens5x5/fc 354.3 ms 357.7 ms +1.0%

@effectfully
Copy link
Contributor Author

^ +0.95% on average out of nowhere. Let's try again.

@effectfully
Copy link
Contributor Author

/benchmark plutus-benchmark:nofib

@github-actions
Copy link
Contributor

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

Comparing benchmark results of ' plutus-benchmark:nofib' on '48a20b623' (base) and '50b077a0c' (PR)

Results table
Script 48a20b6 50b077a Change
clausify/formula1 15.46 ms 15.59 ms +0.8%
clausify/formula2 19.98 ms 20.16 ms +0.9%
clausify/formula3 54.97 ms 54.83 ms -0.3%
clausify/formula4 83.65 ms 83.90 ms +0.3%
clausify/formula5 341.1 ms 340.9 ms -0.1%
knights/4x4 60.15 ms 59.87 ms -0.5%
knights/6x6 158.0 ms 159.4 ms +0.9%
knights/8x8 261.3 ms 262.0 ms +0.3%
primetest/05digits 28.50 ms 28.38 ms -0.4%
primetest/08digits 51.61 ms 51.68 ms +0.1%
primetest/10digits 72.10 ms 72.29 ms +0.3%
primetest/20digits 149.6 ms 150.5 ms +0.6%
primetest/30digits 220.3 ms 221.9 ms +0.7%
primetest/40digits 303.5 ms 306.2 ms +0.9%
primetest/50digits 289.3 ms 292.1 ms +1.0%
queens4x4/bt 10.69 ms 10.80 ms +1.0%
queens4x4/bm 15.13 ms 14.86 ms -1.8%
queens4x4/bjbt1 13.27 ms 13.23 ms -0.3%
queens4x4/bjbt2 13.47 ms 13.46 ms -0.1%
queens4x4/fc 28.56 ms 28.30 ms -0.9%
queens5x5/bt 138.5 ms 140.1 ms +1.2%
queens5x5/bm 173.8 ms 172.2 ms -0.9%
queens5x5/bjbt1 164.3 ms 167.5 ms +1.9%
queens5x5/bjbt2 168.9 ms 171.7 ms +1.7%
queens5x5/fc 355.9 ms 357.4 ms +0.4%

@effectfully
Copy link
Contributor Author

+0.31% on average.

OK, this looks like noise that isn't worth spending time on.

@effectfully effectfully deleted the effectfully/evaluation/statically-unroll-itraverseCounter_ branch April 20, 2023 23:09
@effectfully effectfully restored the effectfully/evaluation/statically-unroll-itraverseCounter_ branch November 24, 2024 06:14
@effectfully effectfully reopened this Nov 24, 2024
@effectfully effectfully force-pushed the effectfully/evaluation/statically-unroll-itraverseCounter_ branch from 50b077a to 366de2b Compare November 24, 2024 06:22
@effectfully
Copy link
Contributor Author

/benchmark validation

3 similar comments
@effectfully
Copy link
Contributor Author

/benchmark validation

@effectfully
Copy link
Contributor Author

/benchmark validation

@effectfully
Copy link
Contributor Author

/benchmark validation

Copy link
Contributor

Click here to check the status of your benchmark.

Copy link
Contributor

Comparing benchmark results of 'validation' on '5eb80f3fe3' (base) and '366de2bce7' (PR)

Results table
Script 5eb80f3 366de2b Change
auction_1-1 239.6 μs 233.1 μs -2.7%
auction_1-2 784.9 μs 769.8 μs -1.9%
auction_1-3 771.6 μs 766.7 μs -0.6%
auction_1-4 311.1 μs 303.0 μs -2.6%
auction_2-1 240.7 μs 233.6 μs -2.9%
auction_2-2 784.7 μs 767.3 μs -2.2%
auction_2-3 1.018 ms 995.4 μs -2.2%
auction_2-4 768.8 μs 764.8 μs -0.5%
auction_2-5 310.6 μs 302.7 μs -2.5%
crowdfunding-success-1 278.8 μs 273.1 μs -2.0%
crowdfunding-success-2 279.2 μs 273.3 μs -2.1%
crowdfunding-success-3 278.8 μs 273.1 μs -2.0%
currency-1 320.6 μs 305.4 μs -4.7%
escrow-redeem_1-1 438.0 μs 433.5 μs -1.0%
escrow-redeem_1-2 439.2 μs 432.5 μs -1.5%
escrow-redeem_2-1 510.4 μs 507.2 μs -0.6%
escrow-redeem_2-2 510.1 μs 505.0 μs -1.0%
escrow-redeem_2-3 510.0 μs 506.5 μs -0.7%
escrow-refund-1 206.7 μs 202.3 μs -2.1%
future-increase-margin-1 311.9 μs 305.7 μs -2.0%
future-increase-margin-2 664.5 μs 655.0 μs -1.4%
future-increase-margin-3 673.5 μs 655.1 μs -2.7%
future-increase-margin-4 600.1 μs 594.4 μs -0.9%
future-increase-margin-5 1.013 ms 980.0 μs -3.3%
future-pay-out-1 312.4 μs 304.5 μs -2.5%
future-pay-out-2 667.5 μs 656.6 μs -1.6%
future-pay-out-3 665.8 μs 652.8 μs -2.0%
future-pay-out-4 997.1 μs 977.7 μs -1.9%
future-settle-early-1 313.2 μs 304.5 μs -2.8%
future-settle-early-2 670.2 μs 653.9 μs -2.4%
future-settle-early-3 667.0 μs 655.2 μs -1.8%
future-settle-early-4 761.9 μs 743.7 μs -2.4%
game-sm-success_1-1 486.5 μs 477.0 μs -2.0%
game-sm-success_1-2 268.0 μs 264.6 μs -1.3%
game-sm-success_1-3 802.1 μs 770.0 μs -4.0%
game-sm-success_1-4 311.8 μs 305.1 μs -2.1%
game-sm-success_2-1 488.7 μs 478.0 μs -2.2%
game-sm-success_2-2 268.3 μs 264.5 μs -1.4%
game-sm-success_2-3 790.4 μs 771.5 μs -2.4%
game-sm-success_2-4 312.3 μs 302.9 μs -3.0%
game-sm-success_2-5 790.2 μs 770.2 μs -2.5%
game-sm-success_2-6 311.3 μs 303.8 μs -2.4%
multisig-sm-1 497.7 μs 486.8 μs -2.2%
multisig-sm-2 491.5 μs 476.7 μs -3.0%
multisig-sm-3 487.3 μs 480.0 μs -1.5%
multisig-sm-4 495.1 μs 480.2 μs -3.0%
multisig-sm-5 677.6 μs 671.1 μs -1.0%
multisig-sm-6 505.8 μs 486.3 μs -3.9%
multisig-sm-7 491.2 μs 476.2 μs -3.1%
multisig-sm-8 487.9 μs 481.8 μs -1.3%
multisig-sm-9 494.6 μs 481.4 μs -2.7%
multisig-sm-10 680.3 μs 669.1 μs -1.6%
ping-pong-1 410.9 μs 403.8 μs -1.7%
ping-pong-2 413.4 μs 403.3 μs -2.4%
ping-pong_2-1 257.6 μs 252.2 μs -2.1%
prism-1 227.0 μs 220.3 μs -3.0%
prism-2 524.1 μs 507.8 μs -3.1%
prism-3 469.7 μs 458.2 μs -2.4%
pubkey-1 190.6 μs 189.1 μs -0.8%
stablecoin_1-1 1.153 ms 1.131 ms -1.9%
stablecoin_1-2 262.0 μs 259.2 μs -1.1%
stablecoin_1-3 1.330 ms 1.298 ms -2.4%
stablecoin_1-4 279.7 μs 272.6 μs -2.5%
stablecoin_1-5 1.705 ms 1.655 ms -2.9%
stablecoin_1-6 342.4 μs 335.1 μs -2.1%
stablecoin_2-1 1.166 ms 1.131 ms -3.0%
stablecoin_2-2 262.2 μs 257.9 μs -1.6%
stablecoin_2-3 1.339 ms 1.296 ms -3.2%
stablecoin_2-4 279.0 μs 274.5 μs -1.6%
token-account-1 241.2 μs 235.5 μs -2.4%
token-account-2 428.4 μs 418.4 μs -2.3%
uniswap-1 499.3 μs 486.0 μs -2.7%
uniswap-2 285.0 μs 279.2 μs -2.0%
uniswap-3 2.130 ms 2.108 ms -1.0%
uniswap-4 445.5 μs 430.2 μs -3.4%
uniswap-5 1.431 ms 1.415 ms -1.1%
uniswap-6 424.1 μs 411.1 μs -3.1%
vesting-1 440.7 μs 425.4 μs -3.5%
5eb80f3 366de2b Change
TOTAL 44.40 ms 43.44 ms -2.2%

Copy link
Contributor

Click here to check the status of your benchmark.

Copy link
Contributor

Comparing benchmark results of 'validation' on '5eb80f3fe3' (base) and '366de2bce7' (PR)

Results table
Script 5eb80f3 366de2b Change
auction_1-1 242.5 μs 231.8 μs -4.4%
auction_1-2 786.7 μs 765.8 μs -2.7%
auction_1-3 773.6 μs 762.7 μs -1.4%
auction_1-4 315.5 μs 300.3 μs -4.8%
auction_2-1 243.5 μs 232.2 μs -4.6%
auction_2-2 795.3 μs 764.4 μs -3.9%
auction_2-3 1.021 ms 993.2 μs -2.7%
auction_2-4 773.3 μs 765.4 μs -1.0%
auction_2-5 320.2 μs 301.4 μs -5.9%
crowdfunding-success-1 282.1 μs 271.6 μs -3.7%
crowdfunding-success-2 284.0 μs 271.7 μs -4.3%
crowdfunding-success-3 283.2 μs 272.2 μs -3.9%
currency-1 314.6 μs 304.8 μs -3.1%
escrow-redeem_1-1 445.0 μs 432.5 μs -2.8%
escrow-redeem_1-2 442.2 μs 430.7 μs -2.6%
escrow-redeem_2-1 514.1 μs 503.5 μs -2.1%
escrow-redeem_2-2 519.4 μs 504.9 μs -2.8%
escrow-redeem_2-3 514.1 μs 504.3 μs -1.9%
escrow-refund-1 209.0 μs 201.0 μs -3.8%
future-increase-margin-1 323.8 μs 304.3 μs -6.0%
future-increase-margin-2 672.2 μs 653.1 μs -2.8%
future-increase-margin-3 673.7 μs 652.6 μs -3.1%
future-increase-margin-4 604.4 μs 594.8 μs -1.6%
future-increase-margin-5 1.004 ms 979.2 μs -2.5%
future-pay-out-1 321.6 μs 304.4 μs -5.3%
future-pay-out-2 671.6 μs 654.4 μs -2.6%
future-pay-out-3 668.7 μs 652.8 μs -2.4%
future-pay-out-4 1.002 ms 977.0 μs -2.5%
future-settle-early-1 315.0 μs 305.1 μs -3.1%
future-settle-early-2 670.8 μs 652.0 μs -2.8%
future-settle-early-3 672.3 μs 654.2 μs -2.7%
future-settle-early-4 770.0 μs 743.9 μs -3.4%
game-sm-success_1-1 492.8 μs 476.4 μs -3.3%
game-sm-success_1-2 272.4 μs 262.9 μs -3.5%
game-sm-success_1-3 809.4 μs 765.6 μs -5.4%
game-sm-success_1-4 317.1 μs 301.8 μs -4.8%
game-sm-success_2-1 490.5 μs 476.6 μs -2.8%
game-sm-success_2-2 272.4 μs 263.3 μs -3.3%
game-sm-success_2-3 794.9 μs 768.5 μs -3.3%
game-sm-success_2-4 317.5 μs 302.4 μs -4.8%
game-sm-success_2-5 787.3 μs 767.7 μs -2.5%
game-sm-success_2-6 317.0 μs 302.1 μs -4.7%
multisig-sm-1 500.2 μs 484.0 μs -3.2%
multisig-sm-2 487.2 μs 474.5 μs -2.6%
multisig-sm-3 487.2 μs 479.2 μs -1.6%
multisig-sm-4 500.7 μs 481.0 μs -3.9%
multisig-sm-5 685.1 μs 670.0 μs -2.2%
multisig-sm-6 499.0 μs 483.5 μs -3.1%
multisig-sm-7 490.4 μs 473.6 μs -3.4%
multisig-sm-8 487.8 μs 476.9 μs -2.2%
multisig-sm-9 506.4 μs 481.1 μs -5.0%
multisig-sm-10 691.5 μs 670.3 μs -3.1%
ping-pong-1 413.1 μs 402.4 μs -2.6%
ping-pong-2 413.4 μs 401.7 μs -2.8%
ping-pong_2-1 259.6 μs 251.2 μs -3.2%
prism-1 230.7 μs 219.5 μs -4.9%
prism-2 527.9 μs 507.3 μs -3.9%
prism-3 474.4 μs 457.3 μs -3.6%
pubkey-1 193.2 μs 187.3 μs -3.1%
stablecoin_1-1 1.166 ms 1.126 ms -3.4%
stablecoin_1-2 266.0 μs 257.4 μs -3.2%
stablecoin_1-3 1.339 ms 1.293 ms -3.4%
stablecoin_1-4 283.5 μs 271.2 μs -4.3%
stablecoin_1-5 1.722 ms 1.651 ms -4.1%
stablecoin_1-6 348.2 μs 332.6 μs -4.5%
stablecoin_2-1 1.173 ms 1.125 ms -4.1%
stablecoin_2-2 265.5 μs 256.6 μs -3.4%
stablecoin_2-3 1.343 ms 1.292 ms -3.8%
stablecoin_2-4 283.4 μs 272.7 μs -3.8%
token-account-1 243.6 μs 234.7 μs -3.7%
token-account-2 428.7 μs 416.4 μs -2.9%
uniswap-1 500.1 μs 484.9 μs -3.0%
uniswap-2 287.1 μs 277.5 μs -3.3%
uniswap-3 2.126 ms 2.099 ms -1.3%
uniswap-4 452.7 μs 429.0 μs -5.2%
uniswap-5 1.439 ms 1.407 ms -2.2%
uniswap-6 428.4 μs 408.7 μs -4.6%
vesting-1 436.9 μs 423.1 μs -3.2%
5eb80f3 366de2b Change
TOTAL 44.70 ms 43.29 ms -3.2%

Copy link
Contributor

Click here to check the status of your benchmark.

Copy link
Contributor

Comparing benchmark results of 'validation' on '5eb80f3fe3' (base) and '366de2bce7' (PR)

Results table
Script 5eb80f3 366de2b Change
auction_1-1 241.0 μs 232.9 μs -3.4%
auction_1-2 785.7 μs 770.4 μs -1.9%
auction_1-3 779.2 μs 765.3 μs -1.8%
auction_1-4 312.9 μs 302.4 μs -3.4%
auction_2-1 241.5 μs 233.1 μs -3.5%
auction_2-2 790.5 μs 768.4 μs -2.8%
auction_2-3 1.019 ms 997.3 μs -2.1%
auction_2-4 779.1 μs 764.7 μs -1.8%
auction_2-5 312.4 μs 301.8 μs -3.4%
crowdfunding-success-1 280.4 μs 272.4 μs -2.9%
crowdfunding-success-2 282.2 μs 272.6 μs -3.4%
crowdfunding-success-3 281.9 μs 272.4 μs -3.4%
currency-1 313.5 μs 305.6 μs -2.5%
escrow-redeem_1-1 442.3 μs 432.4 μs -2.2%
escrow-redeem_1-2 442.5 μs 431.0 μs -2.6%
escrow-redeem_2-1 513.3 μs 506.8 μs -1.3%
escrow-redeem_2-2 516.5 μs 505.4 μs -2.1%
escrow-redeem_2-3 512.6 μs 508.1 μs -0.9%
escrow-refund-1 207.9 μs 201.5 μs -3.1%
future-increase-margin-1 323.5 μs 305.5 μs -5.6%
future-increase-margin-2 671.2 μs 654.0 μs -2.6%
future-increase-margin-3 669.8 μs 653.3 μs -2.5%
future-increase-margin-4 602.1 μs 595.2 μs -1.1%
future-increase-margin-5 997.7 μs 981.3 μs -1.6%
future-pay-out-1 314.0 μs 304.6 μs -3.0%
future-pay-out-2 670.1 μs 653.5 μs -2.5%
future-pay-out-3 668.7 μs 653.6 μs -2.3%
future-pay-out-4 1.007 ms 979.3 μs -2.8%
future-settle-early-1 313.3 μs 304.9 μs -2.7%
future-settle-early-2 668.1 μs 655.1 μs -1.9%
future-settle-early-3 673.2 μs 657.3 μs -2.4%
future-settle-early-4 765.7 μs 746.0 μs -2.6%
game-sm-success_1-1 498.0 μs 476.9 μs -4.2%
game-sm-success_1-2 269.8 μs 264.0 μs -2.1%
game-sm-success_1-3 793.9 μs 771.3 μs -2.8%
game-sm-success_1-4 314.8 μs 303.5 μs -3.6%
game-sm-success_2-1 497.2 μs 478.6 μs -3.7%
game-sm-success_2-2 270.6 μs 264.7 μs -2.2%
game-sm-success_2-3 790.3 μs 770.7 μs -2.5%
game-sm-success_2-4 314.9 μs 303.5 μs -3.6%
game-sm-success_2-5 793.9 μs 770.7 μs -2.9%
game-sm-success_2-6 314.7 μs 303.3 μs -3.6%
multisig-sm-1 506.2 μs 485.6 μs -4.1%
multisig-sm-2 486.1 μs 475.5 μs -2.2%
multisig-sm-3 485.5 μs 478.7 μs -1.4%
multisig-sm-4 495.5 μs 481.6 μs -2.8%
multisig-sm-5 684.1 μs 672.2 μs -1.7%
multisig-sm-6 499.0 μs 485.4 μs -2.7%
multisig-sm-7 488.1 μs 475.7 μs -2.5%
multisig-sm-8 488.3 μs 481.7 μs -1.4%
multisig-sm-9 496.4 μs 481.0 μs -3.1%
multisig-sm-10 682.9 μs 670.4 μs -1.8%
ping-pong-1 416.5 μs 403.6 μs -3.1%
ping-pong-2 413.0 μs 403.6 μs -2.3%
ping-pong_2-1 257.7 μs 252.6 μs -2.0%
prism-1 228.1 μs 219.7 μs -3.7%
prism-2 525.8 μs 509.5 μs -3.1%
prism-3 470.5 μs 458.6 μs -2.5%
pubkey-1 191.5 μs 188.2 μs -1.7%
stablecoin_1-1 1.162 ms 1.130 ms -2.8%
stablecoin_1-2 263.0 μs 257.5 μs -2.1%
stablecoin_1-3 1.324 ms 1.297 ms -2.0%
stablecoin_1-4 281.1 μs 272.6 μs -3.0%
stablecoin_1-5 1.683 ms 1.656 ms -1.6%
stablecoin_1-6 345.2 μs 334.2 μs -3.2%
stablecoin_2-1 1.163 ms 1.131 ms -2.8%
stablecoin_2-2 263.2 μs 257.9 μs -2.0%
stablecoin_2-3 1.341 ms 1.298 ms -3.2%
stablecoin_2-4 280.1 μs 273.4 μs -2.4%
token-account-1 243.7 μs 236.4 μs -3.0%
token-account-2 427.5 μs 417.7 μs -2.3%
uniswap-1 496.2 μs 486.9 μs -1.9%
uniswap-2 286.5 μs 278.6 μs -2.8%
uniswap-3 2.138 ms 2.115 ms -1.1%
uniswap-4 448.6 μs 429.6 μs -4.2%
uniswap-5 1.457 ms 1.415 ms -2.9%
uniswap-6 425.5 μs 411.1 μs -3.4%
vesting-1 437.4 μs 424.8 μs -2.9%
5eb80f3 366de2b Change
TOTAL 44.54 ms 43.44 ms -2.5%

@effectfully effectfully force-pushed the effectfully/evaluation/statically-unroll-itraverseCounter_ branch from 366de2b to 0a8f38e Compare November 25, 2024 04:27
@effectfully
Copy link
Contributor Author

-2.2% to -3.2% with a bunch of readings around -2.5%, so let's call it -2.5%.

@effectfully effectfully requested a review from zliu41 November 25, 2024 06:06
@effectfully effectfully removed the No Changelog Required Add this to skip the Changelog Check label Nov 26, 2024
@effectfully effectfully force-pushed the effectfully/evaluation/statically-unroll-itraverseCounter_ branch from 0a8f38e to 6b3ae4b Compare November 26, 2024 01:59
@effectfully effectfully self-assigned this Nov 26, 2024
@effectfully effectfully requested review from bezirg and kwxm December 4, 2024 13:51
{-# INLINE upwardsM #-}

instance UpwardsM f n => UpwardsM f ('S n) where
upwardsM !i k = k i *> upwardsM @f @n (i + 1) k
Copy link
Contributor

Choose a reason for hiding this comment

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

Weren't you saying somewhere that we should always use (const+i) instead of (i+const)? Not that it changes anything here...

Copy link
Contributor

Choose a reason for hiding this comment

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

I am courious about the possible rationale behind the argument order preference?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the rationale is constant folding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weren't you saying somewhere that we should always use (const+i) instead of (i+const)?

That's in UPLC, I don't think it matters in Haskell, but I'll be happy to get enlightened.

{-# INLINE upwardsM #-}

instance UpwardsM f n => UpwardsM f ('S n) where
upwardsM !i k = k i *> upwardsM @f @n (i + 1) k
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels a bit weird when thinking about the "types" going downwards while in the meantime the values going upwards...

Can't you use them going on the same direction, for example by calling (i-1) instead? Probably you would have to change to (<*) also.

On another note, assuming that NatToPeano is necessary, can't you still keep the KnownNat around so that in the method's definition you call to natVal (Proxy @n) instead of doing the arithmetic manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It feels a bit weird when thinking about the "types" going downwards while in the meantime the values going upwards...

I did exactly what the original implementation did, that's it. I don't think it matters much, but we can discuss it during tech discussion if anybody hates this version.

Probably you would have to change to (<*) also.

That wouldn't change ordering of effects or the result.

On another note, assuming that NatToPeano is necessary, can't you still keep the KnownNat around so that in the method's definition you call to natVal (Proxy @n) instead of doing the arithmetic manually?

Perhaps, but evidently constant folding works perfectly well here (see the GHC Core in the PR description), so who cares?

Comment on lines +84 to +86
data Peano
= Z
| S Peano
Copy link
Contributor

@bezirg bezirg Dec 10, 2024

Choose a reason for hiding this comment

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

Can you explain why Peano is needed? Is it because KnownNat + CmpNat type family would require OverlappingInstances?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it because KnownNat + CmpNat type family would require OverlappingInstances?

Yes. Or interleaving a type family and a type class (like I do here). Or maybe something else. The version in the PR is the simplest I'm aware of.

Comment on lines +106 to +107
{-# INLINE upwardsM #-}

Copy link
Contributor

Choose a reason for hiding this comment

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

How reliable is the use of INLINE pragma?

Let's say that we cannot guarantee that this will be unrolled (fully);
have you looked into the perf difference of old way vs the not-inlined method way? Could the not-inlined method way be actually much slower than the old way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How reliable is the use of INLINE pragma?

In my experience, for such small definitions it is reliable.

have you looked into the perf difference of old way vs the not-inlined method way? Could the not-inlined method way be actually much slower than the old way?

I haven't but I'd expect it to be noticeably slower indeed.

I don't think we need to worry about it, there's a huge tower of abstractions that we optimize away like this. The code here is very straightforward compared to some of the other stuff that we do. There's no way around looking into GHC Core occasionally and relying on longitudinal benchmarks anyway.

-- | Traverse the counters with an effectful function.
itraverseCounter_
:: forall n m
. (KnownNat n, PrimMonad m)
. (UpwardsM m (NatToPeano n), PrimMonad m)
=> (Int -> Word8 -> m ())
-> StepCounter n (PrimState m)
-> m ()
itraverseCounter_ f (StepCounter arr) = do
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems that no other code is using itraverseCounter. How about we get rid of itraversecounter and switch to iforcounter directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel safe to ignore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Meh, it's normal for for to get defined in terms of traverse and having an extra function is fine. I'd keep it the way it is.

instance UpwardsM f n => UpwardsM f ('S n) where
upwardsM !i k = k i *> upwardsM @f @n (i + 1) k
{-# INLINE upwardsM #-}

-- | Traverse the counters with an effectful function.
Copy link
Contributor

@bezirg bezirg Dec 10, 2024

Choose a reason for hiding this comment

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

I was worried about a potential off-by-one mistake. I looked at the core and the unrolling LGTM:

                                 case $weta1_sx2U 0# (ipv8_ivY8 `cast` <Co:8> :: ...) of
                                 { (# ipv10_XX, ipv11_X1a #) ->
                                 case $weta1_sx2U 1# ipv10_XX of { (# ipv12_X1c, ipv13_X11 #) ->
                                 case $weta1_sx2U 2# ipv12_X1c of { (# ipv14_X1d, ipv15_X1e #) ->
                                 case $weta1_sx2U 3# ipv14_X1d of { (# ipv16_X1g, ipv17_X1h #) ->
                                 case $weta1_sx2U 4# ipv16_X1g of { (# ipv18_X1j, ipv19_X1k #) ->
                                 case $weta1_sx2U 5# ipv18_X1j of { (# ipv20_X1m, ipv21_X1n #) ->
                                 case $weta1_sx2U 6# ipv20_X1m of { (# ipv22_X1p, ipv23_X1q #) ->
                                 case $weta1_sx2U 7# ipv22_X1p of { (# ipv24_X1s, ipv25_X1t #) ->
                                 case $weta1_sx2U 8# ipv24_X1s of { (# ipv26_X1v, ipv27_X1w #) ->
                                 case $weta1_sx2U 9# ipv26_X1v of { (# ipv28_X1y, ipv29_X1z #) ->

assuming we have 10 elements on the cekmachinecosts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for double-checking!

-- | Traverse the counters with an effectful function.
itraverseCounter_
:: forall n m
. (KnownNat n, PrimMonad m)
. (UpwardsM m (NatToPeano n), PrimMonad m)
Copy link
Contributor

Choose a reason for hiding this comment

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

So the n is known at compile time, what is it and where does it come from?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is the number of of fields of CekMachineCostsBase

@effectfully
Copy link
Contributor Author

I'm going to claim that I've addressed the comments (by responding to them), so let's merge this bad boy.

@effectfully effectfully merged commit f3fe815 into master Jan 7, 2025
8 checks passed
@effectfully effectfully deleted the effectfully/evaluation/statically-unroll-itraverseCounter_ branch January 7, 2025 05: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