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

Benchmark by fuel usage #514

Open
Kubuxu opened this issue Mar 30, 2022 · 3 comments
Open

Benchmark by fuel usage #514

Kubuxu opened this issue Mar 30, 2022 · 3 comments

Comments

@Kubuxu
Copy link

Kubuxu commented Mar 30, 2022

I would love to know if there is an existing harness to run a benchmark of a given piece of code/function in the context of fuel usage (possibly with wall time timing as well).

@Stebalien
Copy link
Member

Not on a per-function basis, but it would be nice to get fuel usage in https://github.com/filecoin-project/ref-fvm/tree/master/testing/conformance/benches.

@Kubuxu Kubuxu transferred this issue from filecoin-project/builtin-actors Apr 27, 2022
@Kubuxu
Copy link
Author

Kubuxu commented Apr 27, 2022

There is a nice-ish way to do it by implementing an instrumentation gas profiler.
Within wasm-instrumentation introduce two code changes:

  • at the beginning of all functions: introduce a call to a new syscall trace() u64 (syscall only available when ref-fvm is built with a specific feature or maybe runtime toggle).
  • The trace() u64 syscall, saves the current gas used and a backtrace (using Rust side backtrace-rs, symbols don't have to be resolved immediately). The returned u64 is the index of the trace, this index is stored in a new local variable.
  • at all exit points of functions, write current gas to a memory buffer in the form (trace_id, gas). If there are more than N entries in that buffer, the trace() syscall will read the buffer and copy it into Rust-land and clear it in WASM-land.
  • alternative to it would be to call trace(trace_id) or another new syscall.

This would give us all information required to build very precise profiles of execution gas usage at the function level. These profiles can be integrated into existing tooling like flamegraphs or pprof.

At least one syscall per tracepoint is required due to the lack of facilities to gather backtrace info from within WASM.
This, of course, would skew execution timing so it isn't as relevant to setting correct gas values but it is more relevant to optimising actors for fuel usage.

@raulk
Copy link
Member

raulk commented Apr 27, 2022

@Kubuxu This is useful for the Filecoin Core Devs as maintainers of built-in actors, as well as for the dev community, so they can understand how their actors are performing in terms of gas, and can make informed decisions when optimising. Would you be able to write this up in a RFP format so we can consider a devgrant?

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

No branches or pull requests

3 participants