Skip to content

feat: implement high-precision performance tracing in executor#256

Open
vansham wants to merge 4 commits intogenlayerlabs:mainfrom
vansham:main
Open

feat: implement high-precision performance tracing in executor#256
vansham wants to merge 4 commits intogenlayerlabs:mainfrom
vansham:main

Conversation

@vansham
Copy link

@vansham vansham commented Jan 20, 2026

I have added a high-precision execution timer in executor/src/lib.rs using std::time::Instant. This allows the GenVM to log exact execution time in microseconds for every Intelligent Contract call. This is a critical tool for developers to benchmark and optimize their contracts.

Summary by CodeRabbit

  • New Features
    • Execution-time metrics recorded per run and surfaced in performance traces and logs to help spot slow contracts.
    • Configuration now includes runner and registry paths and performs pre-run validation of required addresses and directories, with clear errors on misconfiguration.

✏️ Tip: You can customize this high-level summary in your review settings.

Added performance tracing by tracking execution time and logging metrics.
@CLAassistant
Copy link

CLAassistant commented Jan 20, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

Adds execution-time instrumentation to the executor and expands configuration validation: introduces execution_time_us: u128 to Metrics, uses std::time::Instant to time VM runs and populate/log execution duration, and adds new config fields (runners_dir, registry_dir), derives, and a Config::validate() method called from supervisor creation.

Changes

Cohort / File(s) Summary
Performance timing & metrics
executor/src/lib.rs
Added pub execution_time_us: u128 to Metrics; imported std::time::Instant; instrumented create_supervisor to call config.validate(); instrumented run_with_impl and run_with to record start/end times, set metrics.execution_time_us, and emit performance trace logs with contract address and duration.
Configuration and validation
executor/src/config.rs
Added Serialize, Debug, Clone derives to Module, Modules, and Config; added public fields runners_dir: String and registry_dir: String; introduced pub fn validate(&self) -> Result<()> that checks LLM/Web addresses and cache_dir/runners_dir presence and logs validation success. Updated imports for Serialize, anyhow::Result, and bail.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I tapped my paw upon the clock,
I chased each microsecond tick-tock,
Metrics now gleam from start to end,
Configs checked before we send,
✨⏱️ — a rabbit's hop to ship and stock.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main change: adding execution time tracking in microseconds to the executor's Metrics struct with performance logging.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
executor/src/lib.rs (1)

98-201: Timing is skipped on early error paths
The vm.run().await? and the VM-error early return bypass the log block, so failed calls won’t emit timing even though the intent is “every call.” Consider logging before propagating errors or using a small guard to ensure the log fires on all exits.

🛠️ Minimal fix to log even when vm.run() fails
-    let run_result = vm.run().await?;
+    let run_result = vm.run().await;

     // --- LOG PERFORMANCE METRICS ---
     let exec_duration = start_instant.elapsed().as_micros();
     log_info!(
         contract = %entry_data.message.contract_address,
         duration_us = %exec_duration;
         "Intelligent Contract execution performance trace"
     );
     // -------------------------------
+
+    let run_result = run_result?;

(You’ll still want to route the earlier VM-error return through the same logging path or a guard to cover that branch too.)

🤖 Fix all issues with AI agents
In `@executor/src/lib.rs`:
- Around line 31-33: The Metrics struct's execution_time_us field is never set
so serialized metrics stay zero; either remove the field or wire it to the
actual exec duration: locate where exec_duration is computed in run_with and
assign that value (converted to u128 microseconds) into
Metrics::execution_time_us before serializing/sending, ensuring proper
synchronization if Metrics is shared across threads, or remove execution_time_us
from the Metrics definition and any serialization/consumption sites (and keep
only the logging of exec_duration) to avoid misleading data.

Updated log message to include shared data population and refined comment structure.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@executor/src/lib.rs`:
- Around line 98-100: The timing start (let start_instant = Instant::now()) is
only recorded on the happy path and early returns skip setting execution_time_us
and the log; introduce a small RAII/Drop guard (e.g., ExecutionTimerGuard)
created where start_instant is now, have its Drop impl compute duration, update
execution_time_us and emit the log/metrics, and ensure any references to
start_instant are replaced by or use the guard so that timing is recorded on all
exit paths (including errors and panics); attach the guard at the top of the
function scope that currently contains start_instant so it runs regardless of
how the function returns.

Added serialization support and validation method for Config.
Added configuration validation to ensure proper setup before proceeding.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@executor/src/config.rs`:
- Around line 26-45: The Config::validate method is missing the log_info! macro
import and omits validation for registry_dir; fix by adding the common import
(e.g., bring in genvm_common symbols so log_info! is available) at the top of
the file and extend the validation logic inside Config::validate to check that
self.registry_dir is not empty alongside self.cache_dir and self.runners_dir,
returning a bail! error similar to the existing messages if it is empty; keep
existing checks for modules.llm.address and modules.web.address intact.

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.

2 participants