Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gas cost for UnpackAny #2115

Merged
merged 6 commits into from
Feb 10, 2025
Merged

Add gas cost for UnpackAny #2115

merged 6 commits into from
Feb 10, 2025

Conversation

chipshort
Copy link
Collaborator

breaking for people using a custom Any encoder

Benchmark results:

BenchmarkUnpackAny/garbage_any-8          2235267       521.9 ns/op     136 B/op       4 allocs/op
BenchmarkUnpackAny/single_MsgExec-8       1736608       686.1 ns/op       24 B/op       2 allocs/op
BenchmarkUnpackAny/10000_MsgExec-8        1724133       689.4 ns/op       24 B/op       2 allocs/op
BenchmarkUnpackAny/100000_MsgExec-8       1723904       690.6 ns/op       24 B/op       2 allocs/op

So, it looks like it takes roughly 700ns
Our gas target in CosmWasm uses a target of 1e12 Gas/s = 1e3 Gas/ns. That means:
1e3 Gas/ns * 700ns = 700000 Gas (in CW Gas units)

With the default gas multiplier, it's 5 SDK gas

@chipshort chipshort marked this pull request as draft February 4, 2025 12:48
@chipshort chipshort marked this pull request as ready for review February 4, 2025 12:57
Copy link
Contributor

@pinosu pinosu left a comment

Choose a reason for hiding this comment

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

Great work! LGTM 👍

x/wasm/keeper/handler_plugin_encoders.go Outdated Show resolved Hide resolved
@chipshort
Copy link
Collaborator Author

Ok, I added the constant, but also fixed a bug that I forgot to push the fix for: The gas cost (at least according to my benchmark) seems pretty constant and not related to the message size (see numbers above), so it should not be multiplied with the length

Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.21%. Comparing base (4c5feae) to head (f85d3f6).
Report is 14 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2115   +/-   ##
=======================================
  Coverage   46.20%   46.21%           
=======================================
  Files          78       78           
  Lines       10810    10811    +1     
=======================================
+ Hits         4995     4996    +1     
  Misses       5368     5368           
  Partials      447      447           
Files with missing lines Coverage Δ
x/wasm/keeper/handler_plugin_encoders.go 79.47% <100.00%> (+0.06%) ⬆️

@chipshort chipshort merged commit 4e7c441 into main Feb 10, 2025
19 checks passed
@chipshort chipshort deleted the co/benchmark-unpack-any branch February 10, 2025 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants