Skip to content

Conversation

@brady-stacks
Copy link

@brady-stacks brady-stacks commented Nov 20, 2025

Allow measuring static cost statically for contracts.

  • gives min/max execution cost without executing the contracts
  • gives trait call-counts to determine if excessive cost is incurred by trait calls
  • interfaces with clarinet LSP to give codelens functionality in-editor (here)

@brady-stacks brady-stacks requested review from a team as code owners November 20, 2025 17:14
@CLAassistant
Copy link

CLAassistant commented Nov 20, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ tippenein
❌ brady-stacks
You have signed the CLA already but the status is still pending? Let us recheck it.

@brady-stacks brady-stacks marked this pull request as draft November 20, 2025 17:14
@brady-stacks brady-stacks force-pushed the feat/static-cost branch 2 times, most recently from 17ff3bf to 3560f55 Compare November 21, 2025 18:06
@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

❌ Patch coverage is 63.23296% with 464 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.07%. Comparing base (77f1583) to head (5eeafae).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
clarity/src/vm/costs/analysis.rs 69.33% 184 Missing ⚠️
clarity/src/vm/ast/static_cost/mod.rs 41.73% 134 Missing ⚠️
clarity/src/vm/tests/analysis.rs 49.36% 80 Missing ⚠️
clarity/src/vm/ast/static_cost/trait_counter.rs 75.91% 66 Missing ⚠️

❌ Your project check has failed because the head coverage (58.07%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (77f1583) and HEAD (5eeafae). Click for more details.

HEAD has 72 uploads less than BASE
Flag BASE (77f1583) HEAD (5eeafae)
120 48
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #6704       +/-   ##
============================================
- Coverage    75.65%   58.07%   -17.59%     
============================================
  Files          577      581        +4     
  Lines       357690   358952     +1262     
============================================
- Hits        270624   208446    -62178     
- Misses       87066   150506    +63440     
Files with missing lines Coverage Δ
clarity/src/vm/ast/mod.rs 41.20% <ø> (-28.15%) ⬇️
clarity/src/vm/costs/mod.rs 76.02% <ø> (-7.29%) ⬇️
clarity/src/vm/tests/mod.rs 51.68% <ø> (ø)
clarity/src/vm/ast/static_cost/trait_counter.rs 75.91% <75.91%> (ø)
clarity/src/vm/tests/analysis.rs 49.36% <49.36%> (ø)
clarity/src/vm/ast/static_cost/mod.rs 41.73% <41.73%> (ø)
clarity/src/vm/costs/analysis.rs 69.33% <69.33%> (ø)

... and 403 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77f1583...5eeafae. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

}

/// NativeFunctions -> cost via appropriate cost fn
pub(crate) fn get_cost_function_for_native(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you refactor a bit and use lookup_reserved_functions here? We could probably do some refactoring in the clarity crate to make this easier to use and to ensure that we use the cost functions correctly for those functions that are SpecialFunctions and not NativeFunctions. I think there will be some discrepancies with the way those costs are computed. For example, let passes the length of the bindings list into its cost function, not the length of its total args.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated to use this 👌 . It cleaned up a lot. It did indeed change some costs (len, concat, etc)

Comment on lines 113 to 118
let cost = match clarity_version {
ClarityVersion::Clarity1 => cost_function.eval::<Costs1>(arg_count),
ClarityVersion::Clarity2 => cost_function.eval::<Costs2>(arg_count),
ClarityVersion::Clarity3 => cost_function.eval::<Costs3>(arg_count),
ClarityVersion::Clarity4 => cost_function.eval::<Costs4>(arg_count),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cost contract to use will actually change with the epoch, not with the Clarity version. You may want to pass an epoch in here and use that to select the cost function, or it might make sense to just always default to the latest.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 Passed epoch as well. Ended up defaulting Epoch1.0 to use costs1 since it doesn't have a direct mapping (I think)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants