Cost model for policies (CIP-0168) - #7913
Draft
Unisay wants to merge 1 commit into
Draft
Conversation
Contributor
|
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
force-pushed
the
yura/issue-2309-policies-costing
branch
from
August 21, 2026 12:15
faa2658 to
6b74464
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
policiesbuiltin itself has been inbatch7since 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
Valueon 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.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
Valueand only the list spine is new.Implements IntersectMBO/plutus-private#2309.