Skip to content

Imrpoved costing for equalsByteString and equalsString - #7804

Merged
kwxm merged 5 commits into
masterfrom
kwxm/improved-eqbs-costing
May 29, 2026
Merged

Imrpoved costing for equalsByteString and equalsString#7804
kwxm merged 5 commits into
masterfrom
kwxm/improved-eqbs-costing

Conversation

@kwxm

@kwxm kwxm commented May 29, 2026

Copy link
Copy Markdown
Contributor

This fixes the FIXME comments in the costing function inference code here and here.

The costing functions for equalsByteString and equalsString are linear on the diagonal (ie, when we're comparing two inputs of the same size) and constant off the diagonal (when the inputs have different sizes, in which case they can't possibly be equal). Previously we just ran benchmarks for inputs which were actually equal (which is the worst case) and took the off-diagonal cost to be equal to the minimum of the on-diagonal cost. That was a little inelegant, so this PR adds some benchmark inputs that really are of different sizes, and the R code uses the results for those to determine the off-diagonal cost. Graphs of a test run of the benchmarks are shown below and show that our assumption of constant costs away from the diagonal is reasonable.. The off-diagonal costs determined from the new benchmarks aren't significantly different from the old ones, so I haven't changed the cost models.

Benchmark results for equalsByteString:
equalsByteString

Benchmark results for equalsString:
equalsString

@kwxm kwxm added Builtins Costing Anything relating to costs, fees, gas, etc. No Changelog Required Add this to skip the Changelog Check labels May 29, 2026
@kwxm
kwxm requested review from Unisay and zliu41 May 29, 2026 03:03
@kwxm
kwxm merged commit 5cb073d into master May 29, 2026
9 of 12 checks passed
@kwxm
kwxm deleted the kwxm/improved-eqbs-costing branch May 29, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Builtins Costing Anything relating to costs, fees, gas, etc. No Changelog Required Add this to skip the Changelog Check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants