Skip to content

Add Data.Constr casing to Case - #7914

Open
SeungheonOh wants to merge 7 commits into
masterfrom
sho/caseDataConstr
Open

Add Data.Constr casing to Case#7914
SeungheonOh wants to merge 7 commits into
masterfrom
sho/caseDataConstr

Conversation

@SeungheonOh

Copy link
Copy Markdown
Contributor
case (n : data) of 
  Data.Constr 1 xs -> ...
  Data.Constr 2 xs -> ...
  Data.Constr 3 xs -> ...
  Data.Constr 4 xs -> ...

I discarded this idea originally as most of the cost would've been in the deconstruction of fields(xs here). However, introduction of DropList made deconstruction of xs reasonable fast so this approach actually gives a decent performance boost with minimal change!

@SeungheonOh
SeungheonOh requested review from a team and zliu41 August 20, 2026 05:52
@SeungheonOh SeungheonOh self-assigned this Aug 20, 2026
@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Execution Budget Golden Diff

8a85a9a (master) vs fee879f

output

plutus-benchmark/coop/test/9.6/authMpBurning.golden.eval

Metric Old New Δ%
CPU 126_037_483 101_631_991 -19.36%
Memory 692_234 559_046 -19.24%
Flat Size 5_438 5_300 -2.54%

plutus-benchmark/coop/test/9.6/authMpMinting.golden.eval

Metric Old New Δ%
CPU 298_043_211 246_629_643 -17.25%
Memory 1_624_372 1_343_920 -17.27%
Flat Size 6_835 6_697 -2.02%

plutus-benchmark/coop/test/9.6/certMpBurning.golden.eval

Metric Old New Δ%
CPU 1_794_001_445 1_755_143_033 -2.17%
Memory 10_623_346 10_410_778 -2.00%
Flat Size 7_861 7_709 -1.93%

plutus-benchmark/coop/test/9.6/certMpMinting.golden.eval

Metric Old New Δ%
CPU 344_306_025 291_375_165 -15.37%
Memory 1_905_388 1_616_548 -15.16%
Flat Size 8_384 8_232 -1.81%

plutus-benchmark/coop/test/9.6/fsMpBurning.golden.eval

Metric Old New Δ%
CPU 192_973_826 171_162_330 -11.30%
Memory 1_087_035 967_991 -10.95%
Flat Size 7_206 7_033 -2.40%

plutus-benchmark/coop/test/9.6/fsMpMinting.golden.eval

Metric Old New Δ%
CPU 508_110_602 459_682_086 -9.53%
Memory 2_884_387 2_619_063 -9.20%
Flat Size 9_024 8_851 -1.92%

plutus-benchmark/coop/test/9.6/mustBurnOwnSingleton.golden.eval

Metric Old New Δ%
CPU 92_111_954 77_166_918 -16.22%
Memory 511_897 430_293 -15.94%
Flat Size 3_774 3_644 -3.44%

plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext1-20.golden.eval

Metric Old New Δ%
CPU 85_902_920 68_516_476 -20.24%
Memory 462_058 367_142 -20.54%
Flat Size 1_295 1_164 -10.12%

plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext1-4.golden.eval

Metric Old New Δ%
CPU 25_550_696 20_371_292 -20.27%
Memory 138_058 109_702 -20.54%
Flat Size 909 778 -14.41%

plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext2-20.golden.eval

Metric Old New Δ%
CPU 78_510_086 61_123_642 -22.15%
Memory 429_616 334_700 -22.09%
Flat Size 1_215 1_084 -10.78%

plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext2-4.golden.eval

Metric Old New Δ%
CPU 23_361_190 18_181_786 -22.17%
Memory 128_048 99_692 -22.14%
Flat Size 829 698 -15.80%

plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext1-20.golden.eval

Metric Old New Δ%
CPU 92_522_616 72_084_412 -22.09%
Memory 500_762 389_206 -22.28%
Flat Size 1_397 1_266 -9.38%

plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext1-4.golden.eval

Metric Old New Δ%
CPU 27_680_984 21_891_228 -20.92%
Memory 150_650 118_966 -21.03%
Flat Size 963 832 -13.60%

plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext2-20.golden.eval

Metric Old New Δ%
CPU 85_145_782 64_707_578 -24.00%
Memory 468_420 356_864 -23.82%
Flat Size 1_319 1_188 -9.93%

plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext2-4.golden.eval

Metric Old New Δ%
CPU 25_507_478 19_717_722 -22.70%
Memory 140_740 109_056 -22.51%
Flat Size 885 754 -14.80%

plutus-benchmark/script-contexts/test/V2/9.6/sopFwdStakeTrick.golden.eval

Metric Old New Δ%
CPU 113_334_812 86_182_736 -23.96%
Memory 613_314 465_150 -24.16%
Flat Size 2_040 1_909 -6.42%

plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext1-20.golden.eval

Metric Old New Δ%
CPU 93_083_581 72_492_789 -22.12%
Memory 504_894 392_506 -22.26%
Flat Size 2_077 1_876 -9.68%

plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext1-4.golden.eval

Metric Old New Δ%
CPU 29_009_949 23_067_605 -20.48%
Memory 159_582 127_066 -20.38%
Flat Size 1_643 1_442 -12.23%

plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext2-20.golden.eval

Metric Old New Δ%
CPU 85_690_747 65_099_955 -24.03%
Memory 472_452 360_064 -23.79%
Flat Size 2_000 1_799 -10.05%

plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext2-4.golden.eval

Metric Old New Δ%
CPU 26_820_443 20_878_099 -22.16%
Memory 149_572 117_056 -21.74%
Flat Size 1_566 1_365 -12.84%

plutus-benchmark/script-contexts/test/V3/Data/9.6/purposeIsWellFormed-4.golden.eval

Metric Old New Δ%
Flat Size 697 690 -1.00%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/geq1.golden.eval

Metric Old New Δ%
CPU 327_617_955 324_566_195 -0.93%
Memory 951_025 934_385 -1.75%
Flat Size 933 926 -0.75%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/geq2.golden.eval

Metric Old New Δ%
CPU 337_338_902 334_134_554 -0.95%
Memory 976_851 959_379 -1.79%
Flat Size 984 977 -0.71%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/geq3.golden.eval

Metric Old New Δ%
CPU 348_368_240 345_163_892 -0.92%
Memory 1_009_045 991_573 -1.73%
Flat Size 984 977 -0.71%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/geq4.golden.eval

Metric Old New Δ%
CPU 175_666_243 174_140_363 -0.87%
Memory 521_865 513_545 -1.59%
Flat Size 940 933 -0.74%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/geq5.golden.eval

Metric Old New Δ%
CPU 339_584_990 336_380_642 -0.94%
Memory 983_180 965_708 -1.78%
Flat Size 940 933 -0.74%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/gt1.golden.eval

Metric Old New Δ%
CPU 378_074_360 375_022_600 -0.81%
Memory 1_128_040 1_111_400 -1.48%
Flat Size 1_284 1_277 -0.55%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/gt2.golden.eval

Metric Old New Δ%
CPU 337_562_902 334_358_554 -0.95%
Memory 978_251 960_779 -1.79%
Flat Size 1_335 1_328 -0.52%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/gt3.golden.eval

Metric Old New Δ%
CPU 399_770_345 396_565_997 -0.80%
Memory 1_191_425 1_173_953 -1.47%
Flat Size 1_335 1_328 -0.52%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/gt4.golden.eval

Metric Old New Δ%
CPU 175_890_243 174_364_363 -0.87%
Memory 523_265 514_945 -1.59%
Flat Size 1_291 1_284 -0.54%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.12/gt5.golden.eval

Metric Old New Δ%
CPU 363_647_618 360_443_270 -0.88%
Memory 1_071_104 1_053_632 -1.63%
Flat Size 1_291 1_284 -0.54%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/geq1.golden.eval

Metric Old New Δ%
CPU 327_617_955 324_566_195 -0.93%
Memory 951_025 934_385 -1.75%
Flat Size 933 926 -0.75%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/geq2.golden.eval

Metric Old New Δ%
CPU 337_338_902 334_134_554 -0.95%
Memory 976_851 959_379 -1.79%
Flat Size 984 977 -0.71%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/geq3.golden.eval

Metric Old New Δ%
CPU 348_368_240 345_163_892 -0.92%
Memory 1_009_045 991_573 -1.73%
Flat Size 984 977 -0.71%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/geq4.golden.eval

Metric Old New Δ%
CPU 175_666_243 174_140_363 -0.87%
Memory 521_865 513_545 -1.59%
Flat Size 940 933 -0.74%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/geq5.golden.eval

Metric Old New Δ%
CPU 339_584_990 336_380_642 -0.94%
Memory 983_180 965_708 -1.78%
Flat Size 940 933 -0.74%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/gt1.golden.eval

Metric Old New Δ%
CPU 378_074_360 375_022_600 -0.81%
Memory 1_128_040 1_111_400 -1.48%
Flat Size 1_284 1_277 -0.55%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/gt2.golden.eval

Metric Old New Δ%
CPU 337_562_902 334_358_554 -0.95%
Memory 978_251 960_779 -1.79%
Flat Size 1_335 1_328 -0.52%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/gt3.golden.eval

Metric Old New Δ%
CPU 399_770_345 396_565_997 -0.80%
Memory 1_191_425 1_173_953 -1.47%
Flat Size 1_335 1_328 -0.52%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/gt4.golden.eval

Metric Old New Δ%
CPU 175_890_243 174_364_363 -0.87%
Memory 523_265 514_945 -1.59%
Flat Size 1_291 1_284 -0.54%

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/gt5.golden.eval

Metric Old New Δ%
CPU 363_647_618 360_443_270 -0.88%
Memory 1_071_104 1_053_632 -1.63%
Flat Size 1_291 1_284 -0.54%

plutus-tx-plugin/test/AsData/Budget/9.12/destructSum.golden.eval

Metric Old New Δ%
CPU 3_906_893 3_802_305 -2.68%
Memory 17_344 16_812 -3.07%
Flat Size 171 167 -2.34%

plutus-tx-plugin/test/AsData/Budget/9.12/richSumA.golden.eval

Metric Old New Δ%
CPU 525_432 420_844 -19.91%
Memory 3_164 2_632 -16.81%
Flat Size 111 107 -3.60%

plutus-tx-plugin/test/AsData/Budget/9.12/richSumB.golden.eval

Metric Old New Δ%
CPU 1_165_741 1_061_153 -8.97%
Memory 4_438 3_906 -11.99%
Flat Size 113 109 -3.54%

plutus-tx-plugin/test/AsData/Budget/9.12/richSumC.golden.eval

Metric Old New Δ%
CPU 1_588_996 1_484_408 -6.58%
Memory 6_044 5_512 -8.80%
Flat Size 131 127 -3.05%

plutus-tx-plugin/test/AsData/Budget/9.6/destructSum.golden.eval

Metric Old New Δ%
CPU 3_906_893 3_802_305 -2.68%
Memory 17_344 16_812 -3.07%
Flat Size 171 167 -2.34%

plutus-tx-plugin/test/AsData/Budget/9.6/richSumA.golden.eval

Metric Old New Δ%
CPU 525_432 420_844 -19.91%
Memory 3_164 2_632 -16.81%
Flat Size 111 107 -3.60%

plutus-tx-plugin/test/AsData/Budget/9.6/richSumB.golden.eval

Metric Old New Δ%
CPU 1_165_741 1_061_153 -8.97%
Memory 4_438 3_906 -11.99%
Flat Size 113 109 -3.54%

plutus-tx-plugin/test/AsData/Budget/9.6/richSumC.golden.eval

Metric Old New Δ%
CPU 1_588_996 1_484_408 -6.58%
Memory 6_044 5_512 -8.80%
Flat Size 131 127 -3.05%

plutus-tx-plugin/test/Budget/9.12/map3.golden.eval

Metric Old New Δ%
CPU 110_666_106 109_597_990 -0.97%
Memory 327_856 322_032 -1.78%
Flat Size 704 697 -0.99%

plutus-tx-plugin/test/Budget/9.12/toFromData.golden.eval

Metric Old New Δ%
CPU 176_100 96_100 -45.43%
Memory 1_200 700 -41.67%
Flat Size 24 15 -37.50%

plutus-tx-plugin/test/Budget/9.6/map3.golden.eval

Metric Old New Δ%
CPU 110_666_106 109_597_990 -0.97%
Memory 327_856 322_032 -1.78%
Flat Size 704 697 -0.99%

plutus-tx-plugin/test/Budget/9.6/toFromData.golden.eval

Metric Old New Δ%
CPU 176_100 96_100 -45.43%
Memory 1_200 700 -41.67%
Flat Size 24 15 -37.50%

plutus-tx-plugin/test/IsData/Budget/SoP/9.12/decodeA.golden.eval

Metric Old New Δ%
CPU 560_582 407_994 -27.22%
Memory 2_896 2_064 -28.73%
Flat Size 70 63 -10.00%

plutus-tx-plugin/test/IsData/Budget/SoP/9.12/decodeC.golden.eval

Metric Old New Δ%
CPU 725_790 573_202 -21.02%
Memory 3_298 2_466 -25.23%
Flat Size 69 62 -10.14%

plutus-tx-plugin/test/IsData/Budget/SoP/9.12/decodeMixedNone.golden.eval

Metric Old New Δ%
CPU 360_688 208_100 -42.30%
Memory 2_232 1_400 -37.28%
Flat Size 62 55 -11.29%

plutus-tx-plugin/test/IsData/Budget/SoP/9.12/decodeMixedTwo.golden.eval

Metric Old New Δ%
CPU 874_534 721_946 -17.45%
Memory 4_130 3_298 -20.15%
Flat Size 65 58 -10.77%

plutus-tx-plugin/test/IsData/Budget/SoP/9.12/decodePairA.golden.eval

Metric Old New Δ%
CPU 560_582 407_994 -27.22%
Memory 2_896 2_064 -28.73%
Flat Size 53 46 -13.21%

plutus-tx-plugin/test/IsData/Budget/SoP/9.12/decodePairB.golden.eval

Metric Old New Δ%
CPU 725_790 573_202 -21.02%
Memory 3_298 2_466 -25.23%
Flat Size 53 46 -13.21%

plutus-tx-plugin/test/IsData/Budget/SoP/9.12/decodeSingle.golden.eval

Metric Old New Δ%
CPU 560_582 407_994 -27.22%
Memory 2_896 2_064 -28.73%
Flat Size 39 32 -17.95%

plutus-tx-plugin/test/IsData/Budget/SoP/9.6/decodeA.golden.eval

Metric Old New Δ%
CPU 560_582 407_994 -27.22%
Memory 2_896 2_064 -28.73%
Flat Size 70 63 -10.00%

plutus-tx-plugin/test/IsData/Budget/SoP/9.6/decodeC.golden.eval

Metric Old New Δ%
CPU 725_790 573_202 -21.02%
Memory 3_298 2_466 -25.23%
Flat Size 69 62 -10.14%

plutus-tx-plugin/test/IsData/Budget/SoP/9.6/decodeMixedNone.golden.eval

Metric Old New Δ%
CPU 360_688 208_100 -42.30%
Memory 2_232 1_400 -37.28%
Flat Size 62 55 -11.29%

plutus-tx-plugin/test/IsData/Budget/SoP/9.6/decodeMixedTwo.golden.eval

Metric Old New Δ%
CPU 874_534 721_946 -17.45%
Memory 4_130 3_298 -20.15%
Flat Size 65 58 -10.77%

plutus-tx-plugin/test/IsData/Budget/SoP/9.6/decodePairA.golden.eval

Metric Old New Δ%
CPU 560_582 407_994 -27.22%
Memory 2_896 2_064 -28.73%
Flat Size 53 46 -13.21%

plutus-tx-plugin/test/IsData/Budget/SoP/9.6/decodePairB.golden.eval

Metric Old New Δ%
CPU 725_790 573_202 -21.02%
Memory 3_298 2_466 -25.23%
Flat Size 53 46 -13.21%

plutus-tx-plugin/test/IsData/Budget/SoP/9.6/decodeSingle.golden.eval

Metric Old New Δ%
CPU 560_582 407_994 -27.22%
Memory 2_896 2_064 -28.73%
Flat Size 39 32 -17.95%

This comment will get updated when changes are made.

{-# OPAQUE wrapUnsafeDataAsConstr #-}

wrapCaseData :: BuiltinData -> [BuiltinList BuiltinData -> a] -> a
wrapCaseData = BI.caseData

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you sure we need this? It's possible that neither this nor wrapUnsafeDataAsConstr is needed any more.

If we do, then this needs to be mentioned in the Note below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we don't have this, inliner won't inline the bindings it makes for each fields which prevents DeadCase and CollapseCase pass from running. Can't really think of other ways to make this work better

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On the side note, this method only works on quite specific case where each handler of the match must be lambda directly like so:

matchRich ...
  (\a b c -> ...)
  (\x y z k -> ...)
  ...

if we have non-lambda handler, this doesn't work at all!

let f = \a b c -> ...
in matchRich ...
     f
     (\x y z k -> ...)
     ...

All fields gets bounded for f.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could retire the matcher and try to optimize pattern matching in the plugin. The matcher is already inconvenient to begin with, compared to direct pattern matching. May not be easy to do though.

@zliu41 zliu41 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It otherwise looks good, but this new feature must be gated by dijkstraPV, and I don't think it is gated properly.

@SeungheonOh

Copy link
Copy Markdown
Contributor Author

Do we need this to be gated by dijkstra? I don't think adding this to older PV with builtin casing would have any issue. What do you think?

@zliu41

zliu41 commented Aug 20, 2026

Copy link
Copy Markdown
Member

Do we need this to be gated by dijkstra?

Yes otherwise old node version rejects casing on Constr, new node version accepts it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants