Skip to content

Comments

Optimize VConstr bounds check in CEK machine#7479

Merged
zliu41 merged 1 commit intomasterfrom
yura/issue-7478-cek-vconstr-optimization
Dec 16, 2025
Merged

Optimize VConstr bounds check in CEK machine#7479
zliu41 merged 1 commit intomasterfrom
yura/issue-7478-cek-vconstr-optimization

Conversation

@Unisay
Copy link
Contributor

@Unisay Unisay commented Dec 9, 2025

Summary

Optimizes the CEK machine's handling of VConstr by simplifying type conversions and updating documentation.

Changes

1. Simplified Type Conversion

Before:

| fromIntegral @_ @Integer i > fromIntegral @Int @Integer maxBound ->

After:

| i > fromIntegral @Int @Word64 maxBound ->

Since i is already Word64, we can directly compare it to maxBound :: Int converted to Word64, eliminating the unnecessary intermediate conversion through Integer. This is more efficient and clearer.

2. Updated Documentation

Updated Note [Integral types as Integer] to clarify that all non-64-bit systems (not just 32-bit) are banned for node deployment. Changed wording from "we don't care about" to "64-bit systems are required for" for better tone.

Related

Fixes #7478

Simplify the type conversion in VConstr index validation by
eliminating unnecessary intermediate conversion through Integer.

Changed from:
  fromIntegral @_ @integer i > fromIntegral @int @integer maxBound
To:
  i > fromIntegral @int @Word64 maxBound

Since i is already Word64, we can directly compare it to maxBound
converted to Word64, which is more efficient and clearer.

Also updated Note [Integral types as Integer] to clarify that all
non-64-bit systems (not just 32-bit) are banned for node deployment.

Fixes #7478
@Unisay Unisay requested a review from SeungheonOh December 9, 2025 10:16
@Unisay Unisay self-assigned this Dec 9, 2025
@Unisay Unisay added the No Changelog Required Add this to skip the Changelog Check label Dec 9, 2025
@Unisay Unisay requested a review from a team December 9, 2025 12:27
@SeungheonOh
Copy link
Collaborator

/benchmark validation

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Click here to check the status of your benchmark.

@SeungheonOh
Copy link
Collaborator

/benchmark casing

@SeungheonOh
Copy link
Collaborator

SeungheonOh commented Dec 9, 2025

/benchmark lists

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Comparing benchmark results of 'validation' on 'dd37ea88ba' (base) and 'ab471bee84' (PR)

Results table
Script dd37ea8 ab471be Change
auction_1-1 165.4 μs 165.7 μs +0.2%
auction_1-2 538.7 μs 541.2 μs +0.5%
auction_1-3 532.0 μs 538.3 μs +1.2%
auction_1-4 213.9 μs 215.2 μs +0.6%
auction_2-1 165.8 μs 165.7 μs -0.1%
auction_2-2 535.6 μs 539.6 μs +0.7%
auction_2-3 696.5 μs 699.7 μs +0.5%
auction_2-4 531.3 μs 535.9 μs +0.9%
auction_2-5 213.9 μs 215.5 μs +0.7%
coop-1 226.1 μs 231.2 μs +2.3%
coop-2 726.0 μs 731.5 μs +0.8%
coop-3 2.003 ms 1.982 ms -1.0%
coop-4 885.5 μs 904.9 μs +2.2%
coop-5 389.5 μs 393.9 μs +1.1%
coop-6 670.9 μs 677.3 μs +1.0%
coop-7 323.6 μs 329.3 μs +1.8%
crowdfunding-success-1 193.8 μs 195.9 μs +1.1%
crowdfunding-success-2 193.8 μs 195.4 μs +0.8%
crowdfunding-success-3 194.0 μs 195.3 μs +0.7%
currency-1 215.9 μs 216.3 μs +0.2%
escrow-redeem_1-1 305.5 μs 307.8 μs +0.8%
escrow-redeem_1-2 307.3 μs 307.6 μs +0.1%
escrow-redeem_2-1 355.4 μs 355.5 μs +0.0%
escrow-redeem_2-2 355.3 μs 356.4 μs +0.3%
escrow-redeem_2-3 354.1 μs 356.2 μs +0.6%
escrow-refund-1 143.2 μs 144.2 μs +0.7%
future-increase-margin-1 215.6 μs 216.9 μs +0.6%
future-increase-margin-2 459.9 μs 459.6 μs -0.1%
future-increase-margin-3 459.2 μs 460.6 μs +0.3%
future-increase-margin-4 416.5 μs 418.1 μs +0.4%
future-increase-margin-5 702.9 μs 701.9 μs -0.1%
future-pay-out-1 215.8 μs 216.5 μs +0.3%
future-pay-out-2 458.4 μs 459.7 μs +0.3%
future-pay-out-3 459.1 μs 459.8 μs +0.2%
future-pay-out-4 701.0 μs 701.5 μs +0.1%
future-settle-early-1 215.4 μs 215.9 μs +0.2%
future-settle-early-2 458.5 μs 459.2 μs +0.2%
future-settle-early-3 460.0 μs 459.1 μs -0.2%
future-settle-early-4 531.6 μs 532.7 μs +0.2%
game-sm-success_1-1 335.6 μs 338.7 μs +0.9%
game-sm-success_1-2 185.7 μs 186.6 μs +0.5%
game-sm-success_1-3 537.0 μs 540.0 μs +0.6%
game-sm-success_1-4 214.1 μs 216.6 μs +1.2%
game-sm-success_2-1 337.1 μs 339.3 μs +0.7%
game-sm-success_2-2 185.0 μs 186.3 μs +0.7%
game-sm-success_2-3 536.9 μs 540.0 μs +0.6%
game-sm-success_2-4 214.2 μs 215.9 μs +0.8%
game-sm-success_2-5 537.8 μs 542.2 μs +0.8%
game-sm-success_2-6 214.3 μs 216.4 μs +1.0%
multisig-sm-01 341.8 μs 344.3 μs +0.7%
multisig-sm-02 334.3 μs 334.6 μs +0.1%
multisig-sm-03 335.4 μs 336.9 μs +0.4%
multisig-sm-04 338.0 μs 338.7 μs +0.2%
multisig-sm-05 473.8 μs 474.7 μs +0.2%
multisig-sm-06 339.3 μs 343.5 μs +1.2%
multisig-sm-07 333.6 μs 334.8 μs +0.4%
multisig-sm-08 333.6 μs 335.9 μs +0.7%
multisig-sm-09 336.2 μs 338.2 μs +0.6%
multisig-sm-10 473.5 μs 474.2 μs +0.1%
ping-pong-1 284.2 μs 286.0 μs +0.6%
ping-pong-2 284.1 μs 285.8 μs +0.6%
ping-pong_2-1 178.7 μs 179.6 μs +0.5%
prism-1 154.9 μs 157.4 μs +1.6%
prism-2 352.4 μs 356.8 μs +1.2%
prism-3 322.4 μs 324.0 μs +0.5%
pubkey-1 133.0 μs 133.7 μs +0.5%
stablecoin_1-1 814.2 μs 810.9 μs -0.4%
stablecoin_1-2 181.6 μs 182.7 μs +0.6%
stablecoin_1-3 930.6 μs 927.7 μs -0.3%
stablecoin_1-4 191.6 μs 193.7 μs +1.1%
stablecoin_1-5 1.185 ms 1.182 ms -0.3%
stablecoin_1-6 235.9 μs 239.4 μs +1.5%
stablecoin_2-1 811.5 μs 810.0 μs -0.2%
stablecoin_2-2 180.7 μs 183.1 μs +1.3%
stablecoin_2-3 932.0 μs 928.0 μs -0.4%
stablecoin_2-4 191.5 μs 193.2 μs +0.9%
token-account-1 165.6 μs 166.2 μs +0.4%
token-account-2 290.0 μs 291.8 μs +0.6%
uniswap-1 343.3 μs 342.2 μs -0.3%
uniswap-2 196.8 μs 197.3 μs +0.3%
uniswap-3 1.474 ms 1.478 ms +0.3%
uniswap-4 302.5 μs 308.4 μs +2.0%
uniswap-5 991.0 μs 995.9 μs +0.5%
uniswap-6 289.0 μs 292.6 μs +1.2%
vesting-1 300.4 μs 300.6 μs +0.1%
dd37ea8 ab471be Change
TOTAL 35.84 ms 35.98 ms +0.4%

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Comparing benchmark results of 'casing' on 'dd37ea88ba' (base) and 'ab471bee84' (PR)

Results table
Script dd37ea8 ab471be Change
casing/pairFstSnd/2000 552.8 μs 564.8 μs +2.2%
casing/pairFstSnd/4000 1.218 ms 1.246 ms +2.3%
casing/pairFstSnd/6000 2.049 ms 2.092 ms +2.1%
casing/pairFstSnd/8000 2.956 ms 2.992 ms +1.2%
casing/pairFstSnd/10000 3.902 ms 3.969 ms +1.7%
casing/pairFstSnd/12000 4.730 ms 4.810 ms +1.7%
casing/pairCasing/2000 335.9 μs 332.7 μs -1.0%
casing/pairCasing/4000 788.9 μs 781.6 μs -0.9%
casing/pairCasing/6000 1.433 ms 1.417 ms -1.1%
casing/pairCasing/8000 2.200 ms 2.184 ms -0.7%
casing/pairCasing/10000 3.042 ms 3.010 ms -1.1%
casing/pairCasing/12000 3.935 ms 3.913 ms -0.6%
casing/chooseUnit/2000 225.4 μs 224.8 μs -0.3%
casing/chooseUnit/4000 500.8 μs 501.9 μs +0.2%
casing/chooseUnit/6000 824.7 μs 820.6 μs -0.5%
casing/chooseUnit/8000 1.205 ms 1.203 ms -0.2%
casing/chooseUnit/10000 1.693 ms 1.697 ms +0.2%
casing/chooseUnit/12000 2.271 ms 2.276 ms +0.2%
casing/unitCasing/2000 36.56 μs 38.48 μs +5.3%
casing/unitCasing/4000 72.46 μs 75.62 μs +4.4%
casing/unitCasing/6000 107.9 μs 116.0 μs +7.5%
casing/unitCasing/8000 143.5 μs 148.2 μs +3.3%
casing/unitCasing/10000 178.6 μs 182.9 μs +2.4%
casing/unitCasing/12000 206.5 μs 216.5 μs +4.8%
casing/headList/2000 236.9 μs 246.8 μs +4.2%
casing/headList/4000 494.1 μs 516.8 μs +4.6%
casing/headList/6000 773.9 μs 807.4 μs +4.3%
casing/headList/8000 1.080 ms 1.126 ms +4.3%
casing/headList/10000 1.426 ms 1.484 ms +4.1%
casing/headList/12000 1.814 ms 1.882 ms +3.7%
casing/headListCasing/2000 153.4 μs 151.9 μs -1.0%
casing/headListCasing/4000 328.5 μs 328.1 μs -0.1%
casing/headListCasing/6000 529.0 μs 526.4 μs -0.5%
casing/headListCasing/8000 774.8 μs 769.8 μs -0.6%
casing/headListCasing/10000 1.070 ms 1.062 ms -0.7%
casing/headListCasing/12000 1.421 ms 1.416 ms -0.4%
casing/bool/2000 35.01 μs 38.49 μs +9.9%
casing/bool/4000 70.91 μs 75.74 μs +6.8%
casing/bool/6000 105.9 μs 113.0 μs +6.7%
casing/bool/8000 140.6 μs 149.9 μs +6.6%
casing/bool/10000 181.0 μs 186.7 μs +3.1%
casing/bool/12000 216.8 μs 223.1 μs +2.9%
casing/bool 32.85 μs 35.65 μs +8.5%
casing/bool 64.54 μs 71.21 μs +10.3%
casing/bool 98.12 μs 97.26 μs -0.9%
casing/bool 130.4 μs 138.2 μs +6.0%
casing/bool 163.7 μs 167.1 μs +2.1%
casing/bool 194.8 μs 206.2 μs +5.9%
casing/integer/2000 42.95 μs 47.04 μs +9.5%
casing/integer/4000 83.44 μs 93.58 μs +12.2%
casing/integer/6000 125.2 μs 139.3 μs +11.3%
casing/integer/8000 168.9 μs 187.0 μs +10.7%
casing/integer/10000 195.8 μs 232.4 μs +18.7%
casing/integer/12000 248.8 μs 280.1 μs +12.6%
casing/list/2000 124.0 μs 122.9 μs -0.9%
casing/list/4000 280.1 μs 283.2 μs +1.1%
casing/list/6000 474.3 μs 475.9 μs +0.3%
casing/list/8000 698.7 μs 702.8 μs +0.6%
casing/list/10000 986.4 μs 987.8 μs +0.1%
casing/list/12000 1.348 ms 1.350 ms +0.1%
casing/list 122.3 μs 122.3 μs 0.0%
casing/list 279.4 μs 280.2 μs +0.3%
casing/list 471.6 μs 473.1 μs +0.3%
casing/list 699.0 μs 698.5 μs -0.1%
casing/list 981.8 μs 975.8 μs -0.6%
casing/list 1.338 ms 1.331 ms -0.5%
casing/regularApply/3 589.5 ns 579.5 ns -1.7%
casing/regularApply/10 690.2 ns 687.9 ns -0.3%
casing/regularApply/30 970.3 ns 970.2 ns -0.0%
casing/regularApply/100 2.120 μs 2.098 μs -1.0%
casing/regularApply/500 8.985 μs 8.849 μs -1.5%
casing/regularApply/1000 18.38 μs 18.08 μs -1.6%
casing/caseApply/3 640.8 ns 624.8 ns -2.5%
casing/caseApply/10 784.8 ns 765.3 ns -2.5%
casing/caseApply/30 1.136 μs 1.122 μs -1.2%
casing/caseApply/100 2.756 μs 2.760 μs +0.1%
casing/caseApply/500 11.81 μs 11.90 μs +0.8%
casing/caseApply/1000 23.54 μs 23.88 μs +1.4%
dd37ea8 ab471be Change
TOTAL 54.89 ms 55.49 ms +1.1%

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Comparing benchmark results of 'listst' on 'dd37ea88ba' (base) and 'ab471bee84' (PR)

Results table
Script dd37ea8 ab471be Change
dd37ea8 ab471be Change
TOTAL 0.000 ps 0.000 ps -

@effectfully
Copy link
Contributor

/benchmark lists

@github-actions
Copy link
Contributor

Click here to check the status of your benchmark.

@github-actions
Copy link
Contributor

Comparing benchmark results of 'lists' on 'dd37ea88ba' (base) and 'ab471bee84' (PR)

Results table
Script dd37ea8 ab471be Change
sort/ghcSort/50 186.4 μs 187.4 μs +0.5%
sort/ghcSort/100 431.0 μs 433.9 μs +0.7%
sort/ghcSort/150 741.5 μs 748.7 μs +1.0%
sort/ghcSort/200 1.001 ms 984.2 μs -1.7%
sort/ghcSort/250 1.294 ms 1.296 ms +0.2%
sort/ghcSort/300 1.697 ms 1.710 ms +0.8%
sort/insertionSort/50 617.5 μs 629.1 μs +1.9%
sort/insertionSort/100 2.477 ms 2.511 ms +1.4%
sort/insertionSort/150 5.570 ms 5.673 ms +1.8%
sort/insertionSort/200 9.943 ms 10.14 ms +2.0%
sort/insertionSort/250 15.60 ms 15.90 ms +1.9%
sort/insertionSort/300 22.58 ms 22.96 ms +1.7%
sort/mergeSort/50 567.0 μs 572.1 μs +0.9%
sort/mergeSort/100 1.336 ms 1.309 ms -2.0%
sort/mergeSort/150 2.073 ms 2.106 ms +1.6%
sort/mergeSort/200 2.941 ms 2.946 ms +0.2%
sort/mergeSort/250 3.834 ms 3.870 ms +0.9%
sort/mergeSort/300 4.675 ms 4.706 ms +0.7%
sort/quickSort/50 1.673 ms 1.691 ms +1.1%
sort/quickSort/100 6.942 ms 7.024 ms +1.2%
sort/quickSort/150 15.55 ms 15.74 ms +1.2%
sort/quickSort/200 27.71 ms 27.93 ms +0.8%
sort/quickSort/250 43.47 ms 43.90 ms +1.0%
sort/quickSort/300 62.79 ms 63.34 ms +0.9%
sum/compiled-from-Haskell/sum-right-builtin/100 45.46 μs 45.41 μs -0.1%
sum/compiled-from-Haskell/sum-right-builtin/500 239.4 μs 240.0 μs +0.3%
sum/compiled-from-Haskell/sum-right-builtin/1000 514.6 μs 511.2 μs -0.7%
sum/compiled-from-Haskell/sum-right-builtin/2500 1.682 ms 1.672 ms -0.6%
sum/compiled-from-Haskell/sum-right-builtin/5000 4.046 ms 3.997 ms -1.2%
sum/compiled-from-Haskell/sum-right-Scott/100 47.04 μs 47.35 μs +0.7%
sum/compiled-from-Haskell/sum-right-Scott/500 251.7 μs 252.2 μs +0.2%
sum/compiled-from-Haskell/sum-right-Scott/1000 553.4 μs 553.4 μs 0.0%
sum/compiled-from-Haskell/sum-right-Scott/2500 1.975 ms 1.963 ms -0.6%
sum/compiled-from-Haskell/sum-right-Scott/5000 4.445 ms 4.442 ms -0.1%
sum/compiled-from-Haskell/sum-right-data/100 161.5 μs 160.5 μs -0.6%
sum/compiled-from-Haskell/sum-right-data/500 880.9 μs 878.0 μs -0.3%
sum/compiled-from-Haskell/sum-right-data/1000 2.066 ms 2.053 ms -0.6%
sum/compiled-from-Haskell/sum-right-data/2500 5.935 ms 5.894 ms -0.7%
sum/compiled-from-Haskell/sum-right-data/5000 13.03 ms 12.94 ms -0.7%
sum/compiled-from-Haskell/sum-left-builtin/100 44.53 μs 44.81 μs +0.6%
sum/compiled-from-Haskell/sum-left-builtin/500 232.3 μs 231.4 μs -0.4%
sum/compiled-from-Haskell/sum-left-builtin/1000 499.2 μs 499.9 μs +0.1%
sum/compiled-from-Haskell/sum-left-builtin/2500 1.574 ms 1.582 ms +0.5%
sum/compiled-from-Haskell/sum-left-builtin/5000 3.943 ms 3.936 ms -0.2%
sum/compiled-from-Haskell/sum-left-Scott/100 46.23 μs 46.23 μs 0.0%
sum/compiled-from-Haskell/sum-left-Scott/500 250.7 μs 248.2 μs -1.0%
sum/compiled-from-Haskell/sum-left-Scott/1000 550.0 μs 544.6 μs -1.0%
sum/compiled-from-Haskell/sum-left-Scott/2500 1.882 ms 1.867 ms -0.8%
sum/compiled-from-Haskell/sum-left-Scott/5000 4.440 ms 4.396 ms -1.0%
sum/compiled-from-Haskell/sum-left-data/100 163.2 μs 162.8 μs -0.2%
sum/compiled-from-Haskell/sum-left-data/500 881.6 μs 880.5 μs -0.1%
sum/compiled-from-Haskell/sum-left-data/1000 2.056 ms 2.050 ms -0.3%
sum/compiled-from-Haskell/sum-left-data/2500 5.964 ms 5.935 ms -0.5%
sum/compiled-from-Haskell/sum-left-data/5000 12.58 ms 12.54 ms -0.3%
sum/hand-written-PLC/sum-right-builtin/100 83.74 μs 82.36 μs -1.6%
sum/hand-written-PLC/sum-right-builtin/500 420.8 μs 417.2 μs -0.9%
sum/hand-written-PLC/sum-right-builtin/1000 873.4 μs 864.6 μs -1.0%
sum/hand-written-PLC/sum-right-builtin/2500 2.465 ms 2.433 ms -1.3%
sum/hand-written-PLC/sum-right-builtin/5000 5.194 ms 5.131 ms -1.2%
sum/hand-written-PLC/sum-right-Scott/100 38.90 μs 38.02 μs -2.3%
sum/hand-written-PLC/sum-right-Scott/500 209.3 μs 206.5 μs -1.3%
sum/hand-written-PLC/sum-right-Scott/1000 465.0 μs 457.9 μs -1.5%
sum/hand-written-PLC/sum-right-Scott/2500 1.636 ms 1.624 ms -0.7%
sum/hand-written-PLC/sum-right-Scott/5000 4.677 ms 4.656 ms -0.4%
sum/hand-written-PLC/sum-left-builtin/100 86.69 μs 84.89 μs -2.1%
sum/hand-written-PLC/sum-left-builtin/500 421.0 μs 416.3 μs -1.1%
sum/hand-written-PLC/sum-left-builtin/1000 836.2 μs 825.9 μs -1.2%
sum/hand-written-PLC/sum-left-builtin/2500 2.079 ms 2.056 ms -1.1%
sum/hand-written-PLC/sum-left-builtin/5000 4.139 ms 4.083 ms -1.4%
sum/hand-written-PLC/sum-left-Scott/100 42.31 μs 42.38 μs +0.2%
sum/hand-written-PLC/sum-left-Scott/500 235.0 μs 236.1 μs +0.5%
sum/hand-written-PLC/sum-left-Scott/1000 524.1 μs 527.5 μs +0.6%
sum/hand-written-PLC/sum-left-Scott/2500 1.895 ms 1.900 ms +0.3%
sum/hand-written-PLC/sum-left-Scott/5000 4.772 ms 4.782 ms +0.2%
dd37ea8 ab471be Change
TOTAL 337.8 ms 339.8 ms +0.6%

@effectfully
Copy link
Contributor

/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 'nofib' on 'dd37ea88ba' (base) and 'ab471bee84' (PR)

Results table
Script dd37ea8 ab471be Change
clausify/formula1 1.935 ms 1.922 ms -0.7%
clausify/formula2 2.609 ms 2.601 ms -0.3%
clausify/formula3 7.142 ms 7.124 ms -0.3%
clausify/formula4 15.64 ms 15.56 ms -0.5%
clausify/formula5 34.72 ms 34.41 ms -0.9%
knights/4x4 11.72 ms 11.59 ms -1.1%
knights/6x6 27.56 ms 27.38 ms -0.7%
knights/8x8 47.43 ms 47.13 ms -0.6%
primetest/05digits 5.300 ms 5.387 ms +1.6%
primetest/10digits 10.45 ms 10.65 ms +1.9%
primetest/30digits 30.74 ms 31.12 ms +1.2%
primetest/50digits 50.04 ms 50.48 ms +0.9%
queens4x4/bt 3.486 ms 3.451 ms -1.0%
queens4x4/bm 4.488 ms 4.464 ms -0.5%
queens4x4/bjbt1 4.229 ms 4.186 ms -1.0%
queens4x4/bjbt2 3.961 ms 3.919 ms -1.1%
queens4x4/fc 8.690 ms 8.692 ms +0.0%
queens5x5/bt 47.80 ms 47.24 ms -1.2%
queens5x5/bm 51.95 ms 52.06 ms +0.2%
queens5x5/bjbt1 56.19 ms 55.34 ms -1.5%
queens5x5/bjbt2 54.83 ms 54.29 ms -1.0%
queens5x5/fc 109.3 ms 109.4 ms +0.1%
dd37ea8 ab471be Change
TOTAL 590.2 ms 588.4 ms -0.3%

@zliu41 zliu41 merged commit 13ee473 into master Dec 16, 2025
1 of 3 checks passed
@zliu41 zliu41 deleted the yura/issue-7478-cek-vconstr-optimization branch December 16, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No Changelog Required Add this to skip the Changelog Check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The CEK machine handles VConstr suboptimally

4 participants