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

fix(bench): fix sozo bench #2601

Merged
merged 3 commits into from
Oct 31, 2024
Merged

fix(bench): fix sozo bench #2601

merged 3 commits into from
Oct 31, 2024

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Oct 31, 2024

Summary by CodeRabbit

  • New Features

    • Updated Cairo version and package version for improved performance and compatibility.
    • Introduced a new configuration file for benchmarking with detailed settings for various components and namespaces.
    • Added a benchmark test for the Sozo.Cold component to evaluate performance.
  • Bug Fixes

    • Simplified test configuration by removing unnecessary Cairo plugin dependencies.
  • Documentation

    • Enhanced documentation for the new benchmarking environment and configuration settings.

Copy link

coderabbitai bot commented Oct 31, 2024

Walkthrough

Ohayo, sensei! This pull request introduces several changes across configuration files and a new benchmark test. The Scarb.toml file is updated to reflect a new Cairo version and package version, along with modifications to dependencies. A new configuration file, dojo_dev.toml, is added to define settings for a benchmarking environment. Additionally, the compiler.rs file is simplified by removing Cairo plugin dependencies, and a benchmark for the Sozo.Cold component is introduced, providing performance metrics.

Changes

File Path Change Summary
crates/benches/contracts/Scarb.toml - Updated cairo-version from "2.4.0" to "=2.8.4".
- Incremented package version from "0.4.4" to "1.0.0-rc.0".
- Changed dojo dependency to tagged version "v1.0.0-rc.0".
- Added new dependency starknet with version "=2.8.4".
- Removed sections for [cairo], [tool.dojo], and [tool.dojo.env].
- Added new section [[target.starknet-contract]].
crates/benches/contracts/dojo_dev.toml - Introduced new configuration file with sections: [world], [env], [namespace], [init_call_args], [writers], [owners], and [migration].
crates/dojo/test-utils/src/compiler.rs - Removed CairoPluginRepository import and associated variables from build_test_config function.
- Updated method signature to remove Cairo plugin management.
output_sozo.txt - Added benchmark test for Sozo.Cold with reported time of 4521852125 ns/iter.

Possibly related PRs

  • bench: add sozo build bench for spawn and move #2419: The changes in this PR involve updates to benchmarking processes, which may relate to the modifications in the Scarb.toml file regarding dependencies and versioning, particularly as both PRs focus on enhancing the build and testing environment for the Dojo framework.

Suggested reviewers

  • kariy

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 2

🧹 Outside diff range and nitpick comments (6)
crates/benches/contracts/dojo_dev.toml (4)

1-4: LGTM! Consider documenting the seed choice.

Ohayo! The world configuration looks good, sensei. The predictable seed value "bench" is appropriate for benchmarking purposes.

Consider adding a comment explaining why this specific seed value was chosen to help future maintainers understand the reasoning.


17-19: Document the significance of initialization values.

Ohayo sensei! The hex value 0xfffe is used for both components. Could you please document why this specific value was chosen?

Add a comment explaining the significance of 0xfffe for future maintainers.


21-26: Document the permission structure rationale.

The writers and owners configuration is quite complex, sensei. While it works, it might benefit from documentation explaining why certain namespaces need these specific permissions for the benchmark.

Consider adding comments to explain:

  1. Why ns-M needs write access to both ns and ns2 components
  2. The relationship between writers and owners in this benchmark context

28-30: Document migration configuration decisions.

Ohayo sensei! The migration section would benefit from some context:

  1. Why is this specific initialization order required?
  2. Why is ns-c3 being skipped?

Add comments explaining these configuration choices to help other developers understand the benchmark setup requirements.

crates/dojo/test-utils/src/compiler.rs (2)

Line range hint 196-270: Ohayo! Let's make the file handling more robust, sensei!

The copy_project_temp function could benefit from some improvements:

  1. Several unwrap calls could panic - consider proper error handling
  2. Hard-coded strings like "Scarb.toml" should be constants
  3. Path manipulations could be more robust using proper path joining methods

Here's a suggested improvement for part of the function:

+const SCARB_TOML: &str = "Scarb.toml";
+const WORKSPACE_KEY: &str = "workspace";
+const DEPENDENCIES_KEY: &str = "dependencies";

 if file_name == "Scarb.toml" {
-    let mut contents = String::new();
-    File::open(&dest_path)
-        .and_then(|mut file| file.read_to_string(&mut contents))
-        .unwrap_or_else(|_| panic!("Failed to read {file_name}"));
+    let contents = fs::read_to_string(&dest_path)
+        .map_err(|e| io::Error::new(
+            e.kind(),
+            format!("Failed to read {}: {}", file_name, e)
+        ))?;

Line range hint 1-329: Ohayo! Some architectural suggestions for the test utilities, sensei!

While the simplification of Cairo plugin handling is good, consider these architectural improvements:

  1. Create a dedicated error type for test utilities instead of using raw unwrap()
  2. Consider introducing a builder pattern for test configuration
  3. Add logging for better test debugging

Example error type:

#[derive(Debug, thiserror::Error)]
pub enum TestUtilError {
    #[error("Failed to copy project: {0}")]
    ProjectCopy(#[from] std::io::Error),
    #[error("Config error: {0}")]
    Config(#[from] anyhow::Error),
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 861d0b6 and b63ea45.

⛔ Files ignored due to path filters (1)
  • crates/benches/contracts/Scarb.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • crates/benches/contracts/Scarb.toml (1 hunks)
  • crates/benches/contracts/dojo_dev.toml (1 hunks)
  • crates/dojo/test-utils/src/compiler.rs (1 hunks)
  • output_sozo.txt (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • output_sozo.txt
🧰 Additional context used
🪛 Gitleaks
crates/benches/contracts/dojo_dev.toml

10-10: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (6)
crates/benches/contracts/Scarb.toml (3)

6-7: External contract build configuration looks good, sensei!

The starknet-contract target is correctly configured to build the world contract from dojo.


1-11: Verify removed configurations impact, sensei!

According to the AI summary, several configuration sections were removed ([cairo], [tool.dojo], [tool.dojo.env]). These settings might have moved to the new dojo_dev.toml file.

Let's verify the configuration migration:

#!/bin/bash
# Description: Verify if removed configurations exist in dojo_dev.toml
# Expect: Configurations should be present in dojo_dev.toml

# Check for the presence of dojo_dev.toml
echo "Checking for dojo_dev.toml:"
fd "dojo_dev.toml"

# If found, check its contents for migrated configurations
echo -e "\nChecking for migrated configurations:"
rg "\[(tool\.dojo|cairo|env)\]" -g "dojo_dev.toml"

2-2: Ohayo sensei! Version bump looks good but needs verification.

The cairo-version and package version updates align with the PR objectives for fixing the bench system.

Let's verify the version compatibility:

#!/bin/bash
# Description: Verify cairo version compatibility across the project
# Expect: All Scarb.toml files should use compatible cairo versions

# Search for cairo-version declarations
echo "Checking cairo version declarations:"
rg "cairo-version" -g "Scarb.toml"

# Search for package versions
echo -e "\nChecking package versions:"
rg "^version = " -g "Scarb.toml"

Also applies to: 4-4

crates/benches/contracts/dojo_dev.toml (1)

13-15: LGTM! Clean namespace configuration.

The namespace configuration is well-structured, sensei. The mappings are clear and logical.

crates/dojo/test-utils/src/compiler.rs (2)

9-9: Ohayo! Import cleanup looks good, sensei!

The removal of Cairo plugin-related imports aligns well with the simplification goals.


Line range hint 314-329: Consider maintaining error propagation, sensei!

While simplifying the function is good, removing error handling (anyhow::Result) might hide configuration issues. Even in test utilities, proper error propagation helps with debugging when tests fail.

Let's check how this function is used in the codebase:

Consider keeping the Result type and explicit error handling:

-pub fn build_test_config(path: &str, profile: Profile) -> Config {
+pub fn build_test_config(path: &str, profile: Profile) -> anyhow::Result<Config> {
     let cache_dir = TempDir::new().unwrap();
     let path = Utf8PathBuf::from_path_buf(path.into()).unwrap();
     println!("path: {:?}", path);
-    Config::builder(path.canonicalize_utf8().unwrap())
+    Ok(Config::builder(path.canonicalize_utf8()?)
         .global_cache_dir_override(Some(Utf8Path::from_path(cache_dir.path()).unwrap()))
         .ui_verbosity(Verbosity::Verbose)
         .log_filter_directive(env::var_os("SCARB_LOG"))
         .profile(profile)
-        .build()
+        .build()?)

Comment on lines +10 to +11
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0" }
starknet = "=2.8.4"
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Dependencies are mostly aligned, with one minor inconsistency sensei!

Most of the project uses starknet 2.8.4, but there's one outlier in crates/katana/contracts/Scarb.toml using version 2.8.2. The dojo dependencies are properly configured, with the benches using the git tag that matches the package version (v1.0.0-rc.0).

  • crates/katana/contracts/Scarb.toml: Consider updating starknet from "2.8.2" to "=2.8.4" to maintain consistency
🔗 Analysis chain

Dependencies alignment check needed.

The dojo dependency tag matches the package version, which is good practice. The addition of starknet dependency with a specific version is also appropriate.

Let's verify dependency consistency:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent dependency versions across the project
# Expect: All dojo and starknet dependencies should use compatible versions

# Search for dojo dependencies
echo "Checking dojo dependency declarations:"
rg "dojo = \{" -g "Scarb.toml" -A 2

# Search for starknet dependencies
echo -e "\nChecking starknet dependency declarations:"
rg "^starknet = " -g "Scarb.toml"

Length of output: 1486


Script:

#!/bin/bash
# Let's try a more focused search for dependencies in the specific file and related ones

# Check the specific file's dependencies
echo "Checking dependencies in benches/contracts/Scarb.toml:"
cat crates/benches/contracts/Scarb.toml

# Check dojo dependencies across all Scarb.toml files
echo -e "\nChecking all dojo dependencies:"
rg "dojo.*=.*" -g "Scarb.toml"

# Check starknet dependencies across all Scarb.toml files
echo -e "\nChecking all starknet dependencies:"
rg "starknet.*=.*" -g "Scarb.toml"

Length of output: 2046

Comment on lines +6 to +11
[env]
rpc_url = "http://localhost:5050/"
# Default account for katana with seed = 0
account_address = "0x127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec"
private_key = "0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912"
#world_address = "0x077c0dc7c1aba7f8842aff393ce6aa71fa675b4ced1bc927f7fc971b6acd92fc"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security: Move sensitive data to environment variables.

Ohayo sensei! While this is a development configuration, it's still risky to hardcode private keys in configuration files as they might accidentally be committed to version control.

Consider this safer approach:

[env]
rpc_url = "http://localhost:5050/"
# Default account for katana with seed = 0
-account_address = "0x127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec"
-private_key = "0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912"
+account_address = "${BENCH_ACCOUNT_ADDRESS}"
+private_key = "${BENCH_PRIVATE_KEY}"

Then provide these values through environment variables during benchmarking.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[env]
rpc_url = "http://localhost:5050/"
# Default account for katana with seed = 0
account_address = "0x127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec"
private_key = "0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912"
#world_address = "0x077c0dc7c1aba7f8842aff393ce6aa71fa675b4ced1bc927f7fc971b6acd92fc"
[env]
rpc_url = "http://localhost:5050/"
# Default account for katana with seed = 0
account_address = "${BENCH_ACCOUNT_ADDRESS}"
private_key = "${BENCH_PRIVATE_KEY}"
#world_address = "0x077c0dc7c1aba7f8842aff393ce6aa71fa675b4ced1bc927f7fc971b6acd92fc"
🧰 Tools
🪛 Gitleaks

10-10: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

@glihm glihm merged commit aa039c0 into dojoengine:main Oct 31, 2024
12 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
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.

1 participant