-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Costing for caseList
and caseData
#6929
Draft
kwxm
wants to merge
44
commits into
master
Choose a base branch
from
kwxm/costing/case-list-case-data
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains 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
kwxm
commented
Mar 11, 2025
plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs
Outdated
Show resolved
Hide resolved
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
Builtins
Costing
Anything relating to costs, fees, gas, etc.
No Changelog Required
Add this to skip the Changelog Check
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.
This is an initial attempt to cost the
caseList
andcaseData
builtins, but it's turning out to be a little tricky. The problem is that these functions really return a function and a list of arguments for that function and then the evaluator has to carry on and do some more work to turn this into a real application and evaluate it. I usedλx.()
andλx.λy.()
in the benchmarks and assumed that the cost of evaluating these would be minimal, but that may not be true.Extensive benchmarking shows that both functions are constant time (or at least approximately: see later), but the CPU costs that get inferred from the benchmark results are as follows.
In contrast, the costs for
chooseList
andchooseData
are(These costs are based on some quite old benchmark results, but I re-ran the benchmarks and got numbers that were pretty similar).
The cost of
caseList
exceeds that ofchooseList
by 2164059 units, equivalent to about 135 CEK steps, and the cost ofcaseData
exceeds that ofchooseData
by 4027035 units, or about 251 CEK steps. If we really use these numbers then it'll probably be cheaper to use thechoose
functions (and do some extra work) than it is to use thecase
functions, which kind of defeats the point of adding the builtins.Why is this happening? The mean times for the raw benchmark results are
so the
case
functions are more expensive than thechoose
ones, but only by a factor of 3 or 4, whereas the inferred costs for thecase
functions are 17 and 43 times more expensive than for thechoose
ones. The reason for this is that we try to account for the time taken for the machine to load the function argument in the benchmarks and just cost the time required for actual execution. There are someNop
functions that do nothing except load some arguments and return a constant result, and we subtract these from the raw benchmark results and fit some modelling function to the adjusted data. The time for the two-argumentNop
is 0.838µs and for the six-argumentNop
it's 1.331 µs, and these are quite close to the raw times for thechoose
functions, so the adjusted time is pretty small. However, theNop
times are much smaller than the times for thecase
functions so the adjusted times remain quite large.I think that we really will have to account for the extra work done by the evaluator after the
case
functions return, and it now occurs to me that maybe subtracting theNop
times twice would help because theNop
builtins are very similar to the functions that I've supplied to thecase
builtins in the costing benchmarks. I'll try that and see what happens. [UPDATE: I've tried that and it reduces the cost ofcaseList
from 2790214 to 1328893 and the cost ofcaseData
from 4121410 to 2790214, so it's not that effective.]It would also be useful to have some realistic benchmarks that make a lot of use of the
choose
andcase
builtins so that we can see how the cost model predictions compare to actual execution times.