Skip to content

Cost model for policies (CIP-0168) - #7913

Draft
Unisay wants to merge 1 commit into
masterfrom
yura/issue-2309-policies-costing
Draft

Cost model for policies (CIP-0168)#7913
Unisay wants to merge 1 commit into
masterfrom
yura/issue-2309-policies-costing

Conversation

@Unisay

@Unisay Unisay commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Benchmarks the builtin over 101 values and adds the four resulting parameters to the cost model record, the five JSON variants and the ledger API parameter lists. The policies builtin itself has been in batch7 since 1.67.0.0, so this PR is independent of the rest of the CIP-0168 work.

The model is fitted through the measurements rather than by least squares, which is the part worth reviewing. Cost per policy falls across the range, from 15.2ns below 5000 policies to 14.1ns above 30000, and least squares answers that by trading slope for intercept: it returns an intercept of 7.16us where an empty value measures 0.24us, and that intercept then dominates the charge below roughly 500 policies. Every Value on chain sits far below that. The model charges the largest per-policy rate measured instead, with the intercept set to the largest amount by which any observation exceeds that rate, which puts the line above every measurement.

policies least squares (ps) this model (ps)
1 7172083 259428
10 7297381 403383
39112 551675425 625839873

The benchmark holds one token per policy so that the total size equals the number of policies. Values carrying more tokens per policy have a larger size for the same work, so they are over-charged rather than under-charged.

Memory is charged at three words per cons cell, because the result shares its bytestrings with the Value and only the list spine is new.

Implements IntersectMBO/plutus-private#2309.

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.6.3

🚀 View preview at
https://IntersectMBO.github.io/plutus/pr-preview/cost-models/pr-7913/

Built to branch gh-pages at 2026-08-21 12:27 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Benchmarks the builtin over 101 values and adds the four resulting
parameters to the cost model record, the JSON variants and the ledger API
parameter lists.

The model is fitted through the measurements rather than by least squares.
The cost per policy falls across the range, from 15.2ns below 5000
policies to 14.1ns above 30000, and least squares answers that by trading
slope for intercept: it returns an intercept of 7.16us where an empty
value measures 0.24us, and that intercept then dominates the charge below
roughly 500 policies. Values on chain hold a handful. The model charges
the largest per-policy rate measured instead, with the intercept set to
the largest amount by which any observation exceeds that rate, which is
the measured cost of the empty value. The line sits above every
measurement, over-charges the largest benchmarked values by 16%, and
prices realistic ones around twenty times cheaper than the least-squares
line.

The benchmark holds one token per policy so that the total size equals
the number of policies. Values carrying more tokens per policy have a
larger size for the same work, so they are over-charged rather than
under-charged.

Memory is charged at three words per cons cell: the result shares its
bytestrings with the `Value`, so only the list spine is new.

Implements IntersectMBO/plutus-private#2309.
@Unisay
Unisay force-pushed the yura/issue-2309-policies-costing branch from faa2658 to 6b74464 Compare August 21, 2026 12:15
@Unisay Unisay self-assigned this Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant