Conversation
43759bb to
f2f4424
Compare
f2f4424 to
8a53491
Compare
zliu41
left a comment
There was a problem hiding this comment.
This needs to be backported to the version the Hydra team is using.
759d2f5 to
3f451f2
Compare
5f9e28d to
31f123c
Compare
Update: fixed Marlowe Semantics test failuresRunning the Marlowe benchmark suite ( Root causeThe bug turned out to be in
The old code had a pattern for case 2 that matched The fix adds a recursive Why this wasn't caught earlier
Test results
|
Add golden budget tests for unsafeFromBuiltinData compilation in both SumsOfProducts and BuiltinCasing modes. Covers single-constructor, pair, mixed-arity, and three-constructor types with PIR, UPLC, and evaluation golden files for GHC 9.6 and 9.12.
…ger chain Replace the PlutusTx.List.!! fallback for caseInteger in SoP/Scott mode with an inline equalsInteger/ifThenElse chain that avoids runtime list construction and indexing. Also fix a latent bug in compileHaskellList: the old single-element pattern silently discarded the list tail, so when GHC inlined `build` into an explicit (:)-chain (as it does for recursive types with many constructors like Marlowe's Value and Observation), only the first branch was compiled. The fix adds a recursive consumeCons that walks the full (:) spine.
Regenerate Marlowe flat files and golden budget TSVs to reflect the equalsInteger chain compilation. Semantics SoP validator shrinks from 57663 to 57266 bytes (~0.7%).
3609454 to
7638be5
Compare
Replace runtime list-indexing via PlutusTx.List.!! with a compile-time equalsInteger/ifThenElse chain for the SumsOfProducts caseInteger fallback. This fixes a 3-5x cost regression in unsafeFromBuiltinData for multi-constructor types (reported by Hydra team). Also fixes a latent bug in compileHaskellList that silently dropped list elements when GHC used (:)-chain representation instead of build/foldr form.
* test(IsData/Budget): add SoP and BuiltinCasing budget tests Add golden budget tests for unsafeFromBuiltinData compilation in both SumsOfProducts and BuiltinCasing modes. Covers single-constructor, pair, mixed-arity, and three-constructor types with PIR, UPLC, and evaluation golden files for GHC 9.6 and 9.12. * fix(Compiler/Expr): backport caseInteger SoP fallback fix from #7693 Replace runtime list-indexing via PlutusTx.List.!! with a compile-time equalsInteger/ifThenElse chain for the SumsOfProducts caseInteger fallback. This fixes a 3-5x cost regression in unsafeFromBuiltinData for multi-constructor types (reported by Hydra team). Also fixes a latent bug in compileHaskellList that silently dropped list elements when GHC used (:)-chain representation instead of build/foldr form. * chore: regenerate Marlowe benchmark baselines Updated Marlowe golden TSV files to reflect improved budgets from the caseInteger SoP fix. CPU: -9..12%, Memory: -16..20%. * Release 1.56.0.1
Summary
Closes IntersectMBO/plutus-private#2135.
Fixes the execution cost regression documented in #7691.
When compiling
caseIntegerin the default SumsOfProducts mode, the fallback usedPlutusTx.List.!!, which built a linked list at runtime and indexed into it with a Z-combinator. This caused a 3-5x cost increase forunsafeFromBuiltinDataon multi-constructor types.This PR replaces the fallback with a lazy
equalsInteger/ifThenElsechain in PIR.Uses the
(all dead. resTy)/(/\dead -> branch)encoding to avoid evaluating non-matching branches. No runtime allocation, no Y-combinator, no linked list.How it works
The non-BuiltinCasing branch in
Compiler/Expr.hsnow generates PIR equivalent to:Which erases to
delay/forcein UPLC, matching the pre-regression pattern.The BuiltinCasing branch is unchanged (native
caseon the integer).Budget comparison
data ABC = A Integer | B Integer | C Integer, same source compiled in both modes:SumsOfProducts (default, the regressed mode)
if False)Baseline is generated by bypassing
caseInteger(if FalseinunsafeFromDataClause),which falls back to the old tuple-pattern-matching TH code. The small remaining difference
(~4% for index 0) is from
casePaircontinuation vsfst/sndlet-bindings in thepair extraction, which is inherent to the
caseIntegerTH code path.BuiltinCasing (unaffected by this change)