Skip to content

Conversation

@sanlee42
Copy link
Member

@sanlee42 sanlee42 commented Dec 15, 2025

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

Summary by CodeRabbit

  • New Features

    • Added VM storage mode selection (memory or database backend) via CLI options
    • Added configurable VM concurrency option for benchmarks
    • Made account count parameter optional with intelligent defaults
  • Chores

    • Improved account generation with batching to prevent state overflow
    • Enhanced transaction TTL configuration

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

- Add CLI switches to control VM2 storage backend, concurrency, and reuse num_accounts for both benchmark modes
- Split account creation into smaller persisted batches and cap batch
size to avoid cache eviction and missing nodes
@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Walkthrough

Added a configurable storage mode (VmStorage enum) to benchmark initialization, supporting both in-memory and RocksDB-backed storage. Extended BenchmarkManager to accept account and concurrency overrides. Improved account generation with batch processing to prevent state eviction issues.

Changes

Cohort / File(s) Summary
CLI Configuration
executor/benchmark/src/main.rs
Added vm_storage and vm_concurrency CLI options; changed num_accounts from required to optional; updated BenchmarkManager::new and ::run call signatures to pass storage mode and override parameters.
Benchmark Core Logic
executor/benchmark/src/vm_exec_benchmark.rs
Introduced VmStorage enum (Memory/Db variants); refactored BenchmarkManager::new to accept storage_mode and initialize appropriate storage backend; extended ::run signature with account/concurrency overrides; implemented batch-based account generation (CREATE_BATCH_SIZE) to avoid state eviction; persisted data_dir state in struct.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • BenchmarkManager::new signature change — Verify storage initialization paths for both Memory and Db modes, including optional data_dir handling and genesis setup sequence.
  • BenchmarkManager::run signature change — Confirm account_override and concurrency_override logic, especially clamping behavior for concurrency.
  • Batch processing logic — Review CREATE_BATCH_SIZE batching in account generation and state/cache implications.
  • VmStorage enum integration — Ensure proper propagation through CLI parsing and benchmark initialization.

Possibly related PRs

Suggested labels

ci-runner: k8s

Suggested reviewers

  • welbon
  • nkysg
  • simonjiao
  • jackzhhuang

Poem

🐰 Hoppy times with storage modes so bright,
Memory swift, or RocksDB's might!
Batching accounts in careful chunks we go,
Concurrency tuned—let benchmarks flow!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding CLI options (vm_concurrency, vm_storage) and optimizing the account manager with batching and concurrency improvements.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch vm-bench

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

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9965e2 and b865aea.

📒 Files selected for processing (2)
  • executor/benchmark/src/main.rs (4 hunks)
  • executor/benchmark/src/vm_exec_benchmark.rs (10 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: welbon
Repo: starcoinorg/starcoin PR: 4655
File: cmd/starcoin/src/account/sign_multisig_txn_cmd.rs:61-63
Timestamp: 2025-09-13T14:15:32.756Z
Learning: In Starcoin codebase PR #4655 (Clap v3 to v4 upgrade), maintainer welbon confirmed the preference for minimal configuration changes during the upgrade, specifically declining suggestions to add num_args or value_delimiter attributes to maintain CLI compatibility with existing behavior, even when it might mean less optimal UX compared to new Clap v4 features.
Learnt from: welbon
Repo: starcoinorg/starcoin PR: 4655
File: cmd/resource-code-exporter/src/main.rs:42-44
Timestamp: 2025-09-13T14:13:05.713Z
Learning: In the Starcoin codebase Clap v3 to v4 upgrade (PR #4655), the maintainer welbon prefers minimal configuration changes to ensure compatibility, even if it means slight UX differences, rather than adding additional attributes like num_args or value_delimiter.
Learnt from: welbon
Repo: starcoinorg/starcoin PR: 4633
File: vm/vm-runtime/Cargo.toml:48-48
Timestamp: 2025-09-01T03:56:58.362Z
Learning: In the Starcoin codebase, vm1 (starcoin-vm1-vm-runtime) may need to expose the same feature flags as vm2 to satisfy cross-version compatibility requirements when downstream projects like genesis depend on features from both versions. Empty feature declarations like `move-unit-test = []` may be intentionally added for compilation compatibility rather than to activate specific functionality.
📚 Learning: 2025-09-01T03:56:58.362Z
Learnt from: welbon
Repo: starcoinorg/starcoin PR: 4633
File: vm/vm-runtime/Cargo.toml:48-48
Timestamp: 2025-09-01T03:56:58.362Z
Learning: In the Starcoin codebase, vm1 (starcoin-vm1-vm-runtime) may need to expose the same feature flags as vm2 to satisfy cross-version compatibility requirements when downstream projects like genesis depend on features from both versions. Empty feature declarations like `move-unit-test = []` may be intentionally added for compilation compatibility rather than to activate specific functionality.

Applied to files:

  • executor/benchmark/src/main.rs
  • executor/benchmark/src/vm_exec_benchmark.rs
📚 Learning: 2025-09-16T01:44:35.596Z
Learnt from: lushengguo
Repo: starcoinorg/starcoin PR: 4656
File: vm2/vm-runtime/src/starcoin_vm.rs:1622-1624
Timestamp: 2025-09-16T01:44:35.596Z
Learning: In the Starcoin codebase parallel execution optimization, passing `&data_cache.as_move_resolver()` instead of `data_cache` directly to `execute_user_transaction` is an intentional efficiency optimization to reduce multiple VM-Config loading calls, not a bug.

Applied to files:

  • executor/benchmark/src/main.rs
  • executor/benchmark/src/vm_exec_benchmark.rs
📚 Learning: 2025-09-16T01:34:58.198Z
Learnt from: lushengguo
Repo: starcoinorg/starcoin PR: 4657
File: cmd/starcoin/src/dev/get_coin_cmd.rs:79-90
Timestamp: 2025-09-16T01:34:58.198Z
Learning: In Starcoin's get_coin_cmd.rs batch transaction submission (when repeat > 1), the maintainer lushengguo confirmed the preference for fail-fast behavior using the ? operator - the command should stop on the first transaction failure rather than collecting errors and continuing to submit remaining transactions.

Applied to files:

  • executor/benchmark/src/main.rs
  • executor/benchmark/src/vm_exec_benchmark.rs
📚 Learning: 2025-09-15T13:00:33.502Z
Learnt from: lushengguo
Repo: starcoinorg/starcoin PR: 4659
File: executor/benchmark/src/vm_exec_benchmark.rs:434-435
Timestamp: 2025-09-15T13:00:33.502Z
Learning: In the Starcoin codebase, calling StarcoinVM::set_concurrency_level_once() after running serialized benchmarks is safe, as confirmed by the maintainer. The "once" semantics provide built-in protection against race conditions.

Applied to files:

  • executor/benchmark/src/vm_exec_benchmark.rs
📚 Learning: 2025-09-14T15:08:48.415Z
Learnt from: jackzhhuang
Repo: starcoinorg/starcoin PR: 4648
File: miner/tests/miner_test.rs:87-93
Timestamp: 2025-09-14T15:08:48.415Z
Learning: In Starcoin test files (like miner/tests/miner_test.rs), jackzhhuang prefers to use std::thread::sleep for intentional blocking delays in test scenarios, even within actor event handlers, rather than using non-blocking ctx.run_later alternatives.

Applied to files:

  • executor/benchmark/src/vm_exec_benchmark.rs
📚 Learning: 2025-08-08T10:25:49.039Z
Learnt from: jackzhhuang
Repo: starcoinorg/starcoin PR: 4605
File: txpool/mock-service/src/lib.rs:114-120
Timestamp: 2025-08-08T10:25:49.039Z
Learning: In PR starcoinorg/starcoin#4605, txpool/mock-service/src/lib.rs: MockTxPoolService::next_sequence_number_with_header is currently unused; keeping todo!() in the mock is acceptable and won’t affect runtime unless invoked.

Applied to files:

  • executor/benchmark/src/vm_exec_benchmark.rs
🧬 Code graph analysis (1)
executor/benchmark/src/vm_exec_benchmark.rs (2)
config/src/storage_config.rs (1)
  • cache_size (189-191)
storage/src/storage.rs (2)
  • new_cache_instance_with_capacity (86-90)
  • new_cache_and_db_instance (95-100)
🔇 Additional comments (5)
executor/benchmark/src/vm_exec_benchmark.rs (3)

4-7: VmStorage enum and storage-related imports/constants look consistent

The added imports, storage-related constants (CREATE_BATCH_SIZE, TXN_TTL_SECS), and VmStorage enum (with ValueEnum derive for CLI integration) are cohesive and align with the new CLI-backed storage selection; no issues from a correctness or style perspective.

Also applies to: 11-13, 32-35, 50-54


83-111: Account creation batching and TTL updates are logically correct

Chunking create-account transactions by CREATE_BATCH_SIZE while computing association sequence numbers as a flat chunk_idx * chunk_size + offset preserves a unique, gap-free sequence per txn, and the increased TTL via TXN_TTL_SECS is applied consistently to both creation and transfer txns without changing semantics otherwise.

Also applies to: 133-134


231-235: Storage-mode-aware BenchmarkManager initialization is sound

The new BenchmarkManager::new(storage_mode: VmStorage) cleanly separates in-memory vs RocksDB-backed setups, uses enlarged cache capacity in both modes, initializes genesis once, and retains DataDirPath in _data_dir to keep the RocksDB temp dir alive until drop; the updated Default impl pointing to VmStorage::Memory is also appropriate.

Also applies to: 238-285, 356-359

executor/benchmark/src/main.rs (2)

5-5: CLI option extensions for VM2 benchmarking are well-scoped

Switching num_accounts to Option<usize> and adding vm_concurrency plus vm_storage: VmStorage (with value_enum and a "memory" default) cleanly extends the CLI surface for VM2 benchmarking without over-configuring clap; the options are narrowly targeted and self-documented.

Also applies to: 9-10, 27-34


48-49: Wiring of new options into benchmark paths preserves expected defaults

The VM2 bench path correctly passes vm_storage, num_accounts, and vm_concurrency into BenchmarkManager::new/run, while the non-bench path keeps the historical default of 200 accounts via opt.num_accounts.unwrap_or(200) before calling run_benchmark, so behavior remains predictable with sensible overrides.

Also applies to: 61-66, 69-70, 76-77

Comment on lines 288 to 296
pub fn run(
&mut self,
serialize_bench_txns: &[usize],
parallel_bench_txns: &[usize],
account_override: Option<usize>,
concurrency_override: Option<usize>,
) -> Vec<BenchmarkReport> {
let mut reports = Vec::new();

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Enforce at least 2 accounts to avoid infinite loop in transfer generation

gen_transfer_transactions relies on self.accounts.len() / 2 to drive the inner for loop; if account_num < 2 (e.g., user passes --num-accounts 1), self.accounts.len() / 2 == 0, the for body never runs, and the outer loop never reaches the return, causing an infinite loop when txns_num > 0.

Currently BenchmarkManager::run only bumps account_num from 0 to 1, so this edge case is still reachable via CLI overrides.

Consider clamping to a minimum of 2 accounts:

-        let mut account_num = account_override.unwrap_or_else(|| min(max_txns_once * 2, 20000));
-        if account_num == 0 {
-            account_num = 1;
-        }
+        let mut account_num = account_override.unwrap_or_else(|| min(max_txns_once * 2, 20000));
+        if account_num < 2 {
+            account_num = 2;
+        }

This keeps existing defaults while preventing hangs for small --num-accounts values.

Also applies to: 304-308, 312-316, 324-329

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