Cost model for policies (CIP-0168) - #7921
Merged
Merged
Conversation
Contributor
|
policies keyed on the number of policies (CIP-0168)policies (CIP-0168)
Benchmarks the builtin over 111 values and adds the four resulting parameters to the cost model record, the five JSON variants and the ledger API parameter lists. The work is linear in the number of policies alone, so a new `ValueOuterSize` wrapper threads the outer map size through the denotation, the way `lookupCoin` uses `ValueMaxDepth`. `Map.size` reads a field of the root node, so the measure stays O(1) and does not force the inner maps. Values with a fixed policy count (1000 and 5000) and token counts from 1 to 40 differ by under 5%, with no correlation with the token count, which is what a measure keyed on the outer map predicts. The number of policies is sampled log-uniformly up to 40000, so every decade gets similar coverage, and the cap sits above the largest value a script can build within the CPU budget (roughly 14000 `insertCoin` applications). 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. Closes IntersectMBO/plutus-private#2309.
Unisay
force-pushed
the
yura/issue-2309-policies-outersize
branch
from
August 25, 2026 14:06
71b2fbf to
995c2fb
Compare
Unisay
marked this pull request as ready for review
August 25, 2026 14:30
Contributor
Author
Both generators dispatch on `TypeRep` and call `error` on a type they do not know, so a new size wrapper has to be listed alongside `ValueTotalSize` and `ValueMaxDepth` in each: `genConstant` for the evaluation property tests and `smallConstant` for the cost model safety tests.
Unisay
force-pushed
the
yura/issue-2309-policies-outersize
branch
from
August 26, 2026 10:06
6256fdb to
c4556e3
Compare
kwxm
approved these changes
Aug 27, 2026
kwxm
left a comment
Contributor
There was a problem hiding this comment.
This all looks straightforward: I don't see anything to complain about at all.
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 111 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. Supersedes #7913, which keyed the cost on the total number of (policy, token) pairs.The work of
policiesis linear in the number of policies alone, so a newValueOuterSizewrapper threads the outer map size through the denotation, the waylookupCoinusesValueMaxDepth.Map.sizereads a field of the root node, so the measure stays O(1) and does not force the inner maps. The benchmark backs the measure empirically: values with fixed policy counts (1000 and 5000) and token counts from 1 to 40 differ by under 5%, with no correlation with the token count. The wrapper is reusable for costingkeepPoliciesanddropPolicies.The model is a least-squares linear fit. The number of policies is sampled log-uniformly up to 40000, so every decade gets similar coverage, and the cap sits above the largest value a script can build within the CPU budget (roughly 14000
insertCoinapplications). Memory is charged at three words per cons cell, because the result shares its bytestrings with theValueand only the list spine is new.Implements IntersectMBO/plutus-private#2309.