Commit 4fcf1a3
authored
perf(builtins): optimize listToArray implementation and costing (#7468)
* perf(cost-model): optimize listToArray implementation and costing
Improve listToArray builtin performance and costing precision:
- Use Vector.fromListN instead of Vector.fromList to allocate exact
array size upfront, avoiding incremental resizing overhead
- Implement batched ExMemoryUsage for lists that processes spine in
chunks of 100 elements for more efficient cost computation
- Expand benchmark coverage to 1-5000 element lists for better cost
model fitting across a wider range of input sizes
* perf(cost-model): update listToArray CPU cost parameters
Update listToArray cost model based on new benchmark results. The new
implementation has lower base cost (intercept: 1000 vs 307802) but
higher per-element cost (slope: 24619 vs 8496), reflecting the
optimized algorithm that processes elements more efficiently with
lower overhead.
* docs(cost-models): add visualization pages for array builtins
Add interactive cost model visualization pages for the three array
builtin functions: ListToArray, LengthOfArray, and IndexArray. Each
page displays benchmark data alongside fitted cost model predictions,
following the established pattern for existing function visualizations.
* test(conformance): update listToArray budget expectations
Update expected CPU budgets for listToArray conformance tests to
reflect the updated cost model parameters (lower intercept, higher
slope).
* refactor(core): add PlutusCore.Unroll module for static loop unrolling
Extract Peano numbers, NatToPeano type family, and static unrolling utilities into a dedicated module. This consolidates type-level machinery for compile-time loop unrolling previously duplicated in StepCounter.
Provides Drop class for statically unrolled list operations and UpwardsM class for statically unrolled effectful iteration.
* refactor(cek): use PlutusCore.Unroll in StepCounter
Remove duplicated Peano, NatToPeano, and UpwardsM definitions from StepCounter and import them from PlutusCore.Unroll instead. Reduces code duplication while maintaining identical runtime behavior.
* perf(costing): use statically unrolled drop for list memoryUsage
Replace splitAt with dropN in the ExMemoryUsage instance for lists. The dropN function uses compile-time instance resolution to unroll the drop operation, avoiding tuple and prefix list allocation that splitAt requires.
* Update CPU slope in cost models A, B, and C to improve performance estimation
- Changed the slope value from 24619 to 24838 in builtinCostModelA.json
- Changed the slope value from 24619 to 24838 in builtinCostModelB.json
- Changed the slope value from 24619 to 24838 in builtinCostModelC.json
* test(conformance): update listToArray-02 budget expectation
Adjust budget expectation for listToArray-02 test case to reflect the
updated CPU slope in the cost model (286671 → 288642 cpu).
* fix(cost-models): use Nop*o pattern for overhead calculation in JS
Match R's models.R which uses Opaque (Nop*o) benchmarks for overhead
calculation. The JS visualization was incorrectly using Nop*b pattern.
* fix(cost-models): regenerate indexArray and lengthOfArray CPU costs
These values were incorrect since commit 69cb3d9. Regenerated using
generate-cost-model tool from current benching-conway.csv data.1 parent 637c5be commit 4fcf1a3
File tree
24 files changed
+1792
-159
lines changed- doc/cost-models
- indexarray
- lengthofarray
- listtoarray
- lookupcoin
- unvaluedata
- valuecontains
- valuedata
- plutus-conformance/test-cases/uplc/evaluation/builtin/semantics/listToArray
- listToArray-01
- listToArray-02
- plutus-core
- cost-model
- budgeting-bench/Benchmarks
- data
- plutus-core/src/PlutusCore
- Default
- Evaluation/Machine
- untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek
24 files changed
+1792
-159
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
82 | 109 | | |
83 | 110 | | |
84 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
0 commit comments