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

opt(torii): indexing model schema retrieval #2319

Merged
merged 3 commits into from
Aug 21, 2024

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Aug 20, 2024

we use the model cache to avoid fetching the models scheam & parsing every time we index a model state update

Summary by CodeRabbit

  • New Features

    • Introduced a new Model struct for improved data representation in the cache.
    • Enhanced model retrieval efficiency by implementing caching mechanisms in the Sql struct.
  • Bug Fixes

    • Improved logging and data access performance by switching from method calls to direct property access.
  • Refactor

    • Updated several method return types and signatures to align with new structural changes, streamlining the codebase and enhancing clarity.
  • Chores

    • Simplified error handling in model retrieval methods, contributing to cleaner code.

Copy link

coderabbitai bot commented Aug 20, 2024

Walkthrough

Ohayo, sensei! The changes enhance our codebase by introducing a structured Model representation, replacing the generic Ty type. This shift improves clarity and efficiency in data handling, particularly in caching and retrieval operations. Additionally, many asynchronous method calls have been replaced with direct property accesses, simplifying control flow and potentially boosting performance across various processors.

Changes

Files Summary of Changes
crates/torii/core/src/cache.rs Introduced a new Model struct to replace Ty. Updated ModelCache to utilize RwLock<HashMap<Felt, Model>>. Renamed methods accordingly.
crates/torii/core/src/processors/event_message.rs, store_del_record.rs, store_set_record.rs Modified property accesses from method calls to direct field accesses for name and schema, enhancing performance and simplifying code.
crates/torii/core/src/sql.rs Added model_cache field to Sql struct. Updated model method to return Result<Model> instead of Result<ModelSQLReader>, streamlining retrieval.
crates/torii/grpc/src/server/mod.rs, subscriptions/entity.rs, subscriptions/event_message.rs Switched from direct schema retrieval to first fetching models and then extracting schemas, altering the data processing flow for clarity.
crates/torii/libp2p/src/server/mod.rs Removed async call to schema() in validate_message, replacing it with direct property access, which introduces a risk of unhandled errors.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ModelCache
    participant Sql
    participant Model

    Client->>Sql: Request Model
    Sql->>ModelCache: Retrieve Model
    ModelCache-->>Sql: Return Model
    Sql-->>Client: Return Result<Model>
Loading
sequenceDiagram
    participant Client
    participant Cache
    participant Model

    Client->>Cache: Request Models
    Cache-->>Client: Return Models
    Client->>Client: Map to Schemas
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 08cc01d and 850f10e.

Files selected for processing (1)
  • crates/torii/core/src/cache.rs (2 hunks)
Additional comments not posted (7)
crates/torii/core/src/cache.rs (7)

4-4: Ohayo, sensei! Import looks good.

The addition of the Layout import is appropriate for the Model struct.


12-28: Ohayo, sensei! The Model struct is well-defined.

The new Model struct provides a clear and specific representation, improving clarity and data handling.


33-33: Ohayo, sensei! Cache update is consistent.

The ModelCache struct now uses Model, aligning with the new struct definition.


41-49: Ohayo, sensei! Method renaming is spot on.

The models method correctly reflects the new Model struct and ensures type consistency.


50-58: Ohayo, sensei! Method update is consistent.

The model method aligns with the new Model struct, maintaining consistency.


Line range hint 61-113: Ohayo, sensei! Cache update logic is solid.

The update_model method effectively constructs and caches a Model instance, aligning with the new struct.


113-115: Ohayo, sensei! Clear method remains effective.

The clear method is consistent with the ModelCache implementation.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

codecov bot commented Aug 20, 2024

Codecov Report

Attention: Patch coverage is 66.23377% with 26 lines in your changes missing coverage. Please review.

Project coverage is 67.20%. Comparing base (4f76fd7) to head (850f10e).
Report is 4 commits behind head on main.

Files Patch % Lines
crates/torii/grpc/src/server/mod.rs 11.11% 16 Missing ⚠️
...s/torii/core/src/processors/store_update_member.rs 0.00% 3 Missing ⚠️
...s/torii/core/src/processors/store_update_record.rs 0.00% 3 Missing ⚠️
crates/torii/core/src/processors/event_message.rs 0.00% 2 Missing ⚠️
...ates/torii/grpc/src/server/subscriptions/entity.rs 0.00% 1 Missing ⚠️
...rii/grpc/src/server/subscriptions/event_message.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2319      +/-   ##
==========================================
+ Coverage   66.18%   67.20%   +1.02%     
==========================================
  Files         352      352              
  Lines       46739    46266     -473     
==========================================
+ Hits        30933    31095     +162     
+ Misses      15806    15171     -635     

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

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Good opti for speed, quick question do you know the eviction policy for this cache? Or we will just have the RAM growing the more models we have?

@Larkooo Larkooo merged commit 54a891e into dojoengine:main Aug 21, 2024
15 checks passed
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