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

sozo: make inspect faster #3056

Merged
merged 1 commit into from
Feb 21, 2025
Merged

sozo: make inspect faster #3056

merged 1 commit into from
Feb 21, 2025

Conversation

notV4l
Copy link
Collaborator

@notV4l notV4l commented Feb 20, 2025

around 10x faster in my case (from 64s to 6s)

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Improved resource loading stability by ensuring only relevant files are processed and that library assets are accurately tracked.
  • Refactor
    • Updated the file reading process to load content into memory before processing, enhancing reliability and performance.
  • Enhancements
    • Added a mechanism to ignore specific file types during processing, improving the efficiency of resource handling.

Copy link

coderabbitai bot commented Feb 20, 2025

Ohayo, sensei! Here’s the update summary:

Walkthrough

This update refines the logic in the from_directory method of the WorldLocal implementation. The method now skips over files ending with .sierra.json by logging a trace message and continuing the iteration. It also changes the JSON deserialization process by reading file contents into a byte vector and using serde_json::from_slice instead of reading from a file handle. Additionally, the code sets a dojo_resource_found flag when library resources are processed, ensuring accurate resource tracking.

Changes

File Change Summary
crates/.../artifact_to_local.rs - Added a conditional check to skip files ending with .sierra.json with a trace log
- Replaced serde_json::from_reader with serde_json::from_slice after reading bytes
- Set the dojo_resource_found flag when library resources are detected

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant W as WorldLocal::from_directory
    participant FS as File System
    participant JSON as serde_json::from_slice

    U->>W: Call from_directory(dir, profile_config)
    W->>FS: List files in directory
    loop For each file
        W->>W: Check if file ends with ".sierra.json"
        alt File ends with ".sierra.json"
            W->>W: Log trace and skip file
        else
            W->>FS: Read file content into bytes
            W->>JSON: Deserialize file content
            alt Resource is a library file
                W->>W: Set dojo_resource_found flag to true
            end
        end
    end
    W->>U: Return WorldLocal instance
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (2)
crates/dojo/world/src/local/artifact_to_local.rs (2)

169-171: Consider moving the flag update, sensei.

The dojo_resource_found flag update could be moved before the else block to maintain consistency with other resource types where the flag is set immediately after adding resources.

-                                } else {
-                                    dojo_resource_found = true;
-                                }
+                                    dojo_resource_found = added_resources;
+                                }

30-364: Consider adding error metrics for better observability, sensei.

While the performance improvements are great, consider adding metrics to track:

  1. Number of skipped .sierra.json files
  2. Time spent in JSON deserialization
  3. Number of resources processed

This would help monitor the performance improvements in production.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 702d712 and 8b3683a.

📒 Files selected for processing (1)
  • crates/dojo/world/src/local/artifact_to_local.rs (4 hunks)
🔇 Additional comments (3)
crates/dojo/world/src/local/artifact_to_local.rs (3)

49-52: Ohayo! Nice optimization to skip redundant files, sensei!

The addition of this check to skip .sierra.json files is a great performance improvement, as it prevents unnecessary processing of duplicate data.


54-56: Excellent performance optimization using from_slice, sensei!

Switching from from_reader to from_slice is a significant performance improvement. Reading the entire file into memory first and then deserializing from a byte slice is generally faster than reading and parsing incrementally from a file handle.

Also applies to: 64-66


371-371: Consistent use of from_slice here too, sensei!

Good consistency in using from_slice for JSON deserialization in casm_class_hash_from_sierra_file as well.

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 57.65%. Comparing base (f244197) to head (8b3683a).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/dojo/world/src/local/artifact_to_local.rs 70.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3056   +/-   ##
=======================================
  Coverage   57.65%   57.65%           
=======================================
  Files         439      439           
  Lines       59437    59442    +5     
=======================================
+ Hits        34267    34272    +5     
  Misses      25170    25170           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glihm glihm enabled auto-merge (squash) February 21, 2025 18:34
@glihm glihm merged commit 467cad1 into main Feb 21, 2025
15 checks passed
@glihm glihm deleted the fast_sozo_inspect branch February 21, 2025 18:34
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