feat: native builtin data vs th builtin data benchmark#7562
feat: native builtin data vs th builtin data benchmark#7562colll78 wants to merge 3 commits intoIntersectMBO:masterfrom
Conversation
| (\_ -> True) | ||
| BI.unitval | ||
| ) | ||
| BI.unitval |
There was a problem hiding this comment.
I did an experiment and results demonstate that multiway-if compiled by the plugin is actually better than hand-rolled lazy ifthenelse pattern you employ here:
#7578
There was a problem hiding this comment.
Good point, I guess similar could be achieved with ifThenElseLazy predicate ~a ~b = BI.ifThenElse predicate a b right? And if the branches don't contain an error and the terms are small (ie. for && which has only True and False as branches, then we would want to use BI.ifThenElse because multiway if isn't smart enough to know whether it can be safely optimized to strict (and whether it should based on the terms in the branches).
I'll update the implementation to use multiway if, I'm sure it could be further optimized, but I just did a rough translated to BuiltinData and didn't put much effort into optimization and it is already optimized to around 35% of the budget of the TH Data version.
…udget Compare 4 patterns for chaining boolean conditions in Plutus Tx: 1. Standard && (lazy, delay/force) 2. builtinAnd (lambda/unit, Philip DiSarro's pattern from PR #7562) 3. Multi-way if (negated guards) 4. Direct BI.ifThenElse chain (manual lambda/unit) Each pattern tested with 3 scenarios: AllTrue, EarlyFail, LateFail.
Extract patterns 2 and 4 into Budget.BuiltinAndLib with the exact GHC flags used in PR #7562's ValidatorOptimized.hs: - All -fno-* optimisation flags - conservative-optimisation plugin option - INLINE pragmas (not INLINEABLE) Results unchanged: builtinAnd still doesn't short-circuit (839,970 CPU in all scenarios) because Bool arguments are evaluated eagerly before the function body runs, regardless of INLINE/flags.
… experiment Add two more patterns to the && vs builtinAnd comparison: Pattern 5 (andBuiltinAndIfError): Philip's exact claimed usage - if (builtinAnd a $ builtinAnd b c) then ok else error Result: 919,970 CPU, no short-circuiting (all conditions evaluated) Pattern 6 (andBuiltinIfNest): Nested builtinIf with conditions in lambda bodies (Philip's actual validator pattern from PR #7562) Result: 727,970 CPU AllTrue, with proper short-circuiting
Introduce a ScriptContext builder module in plutus-ledger-api testlib that provides composable combinators for constructing ScriptContext values in tests. This replaces hand-crafted script contexts with a declarative builder pattern using lenses. Key changes: - Add PlutusLedgerApi.Test.ScriptContextBuilder.Builder with combinators for minting, spending, certifying, rewarding, and proposing contexts - Add PlutusLedgerApi.Test.ScriptContextBuilder.Lenses with TH-generated lenses for all V3 ledger types - Refactor LinearVesting benchmark tests to use the new builder - Fix AsData destructSum-manual test to use manual IsData instances instead of asData, regenerating golden files Based on work from PR #7562. Co-authored-by: Philip DiSarro <philip-disarro@users.noreply.github.com>
Introduce a ScriptContext builder module in plutus-ledger-api testlib that provides composable combinators for constructing ScriptContext values in tests. This replaces hand-crafted script contexts with a declarative builder pattern using lenses. Key changes: - Add PlutusLedgerApi.Test.ScriptContextBuilder.Builder with combinators for minting, spending, certifying, rewarding, and proposing contexts - Add PlutusLedgerApi.Test.ScriptContextBuilder.Lenses with TH-generated lenses for all V3 ledger types - Refactor LinearVesting benchmark tests to use the new builder - Fix AsData destructSum-manual test to use manual IsData instances instead of asData, regenerating golden files Based on work from PR #7562. Co-authored-by: Philip DiSarro <philip-disarro@users.noreply.github.com>
…7643) * Add ScriptContext Builder testlib and refactor LinearVesting tests Introduce a ScriptContext builder module in plutus-ledger-api testlib that provides composable combinators for constructing ScriptContext values in tests. This replaces hand-crafted script contexts with a declarative builder pattern using lenses. Key changes: - Add PlutusLedgerApi.Test.ScriptContextBuilder.Builder with combinators for minting, spending, certifying, rewarding, and proposing contexts - Add PlutusLedgerApi.Test.ScriptContextBuilder.Lenses with TH-generated lenses for all V3 ledger types - Refactor LinearVesting benchmark tests to use the new builder - Fix AsData destructSum-manual test to use manual IsData instances instead of asData, regenerating golden files Based on work from PR #7562. Co-authored-by: Philip DiSarro <philip-disarro@users.noreply.github.com> * Replace redundant helpers with existing API functions - Replace local isPubKeyAddress/isScriptAddress with toPubKeyHash/toScriptHash from PlutusLedgerApi.V1.Address - Replace negateValue with PlutusTx.negate (Value has AdditiveGroup) - Export and relocate currencySymbolFromHex and singleCurrencySymbol to a dedicated Helpers section at the bottom of Builder.hs Co-authored-by: Philip DiSarro <philip-disarro@users.noreply.github.com> * Regenerate golden files for LinearVesting and CallTrace tests --------- Co-authored-by: Philip DiSarro <philip-disarro@users.noreply.github.com>
|
Optimized linear vesting validator #7658 |
Added a benchmark using very crude and barely optimized native builtin data functions to compare against the existing Vesting contract implemented with TH AsData stuff.
Added script context builder for constructing realistic script contexts which obey ledger invariants.