Skip to content

Conversation

xzfc
Copy link
Contributor

@xzfc xzfc commented Mar 12, 2025

The BitSlice::get() method returns BitRef which requires additional gymnastics to convert it to bool to the point that rustfmt splits such long method call chains into multiple lines.

This PR adds BitSliceExt::get_bit(), making code working with it less bulky.

The following queries were used to find usages to replace:

ast-grep -p '$_.get($_).as_deref().copied()'
ast-grep -p '$_.get($_).map(|$_| *$_)'

@xzfc xzfc requested review from timvisee and generall March 12, 2025 19:51
Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new workspace dependency on the bitvec crate by updating the Cargo.toml file. A new trait, BitSliceExt, is added in the common module with a method get_bit that streamlines the retrieval of bit values. The implementation of this trait for BitSlice replaces previous multi-step chains (using get, as_deref(), and copied()) with a direct method call. Subsequent changes in various modules, including those handling memory mappings, ID tracking, vector storage (dense, multi-dense, sparse), and index filtering, consistently replace the older bit access methods with the new get_bit method. These modifications standardize the process of checking deletion flags and boolean retrievals across the codebase without altering the overall logic.

Suggested reviewers

  • timvisee
  • generall
  • agourlay

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a52a87 and 67f0091.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (15)
  • lib/common/common/Cargo.toml (1 hunks)
  • lib/common/common/src/ext.rs (2 hunks)
  • lib/segment/src/common/mmap_bitslice_buffered_update_wrapper.rs (2 hunks)
  • lib/segment/src/id_tracker/id_tracker_base.rs (3 hunks)
  • lib/segment/src/id_tracker/immutable_id_tracker.rs (2 hunks)
  • lib/segment/src/index/field_index/bool_index/simple_bool_index.rs (2 hunks)
  • lib/segment/src/index/field_index/numeric_index/immutable_numeric_index.rs (3 hunks)
  • lib/segment/src/index/hnsw_index/hnsw.rs (2 hunks)
  • lib/segment/src/segment/formula_rescore.rs (2 hunks)
  • lib/segment/src/vector_storage/async_raw_scorer.rs (2 hunks)
  • lib/segment/src/vector_storage/dense/mmap_dense_vectors.rs (2 hunks)
  • lib/segment/src/vector_storage/dense/simple_dense_vector_storage.rs (2 hunks)
  • lib/segment/src/vector_storage/multi_dense/simple_multi_dense_vector_storage.rs (2 hunks)
  • lib/segment/src/vector_storage/raw_scorer.rs (2 hunks)
  • lib/segment/src/vector_storage/sparse/simple_sparse_vector_storage.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: test-shard-snapshot-api-s3-minio
  • GitHub Check: Basic TLS/HTTPS tests
  • GitHub Check: test-snapshot-operations-s3-minio
  • GitHub Check: test-low-resources
  • GitHub Check: test-consistency
  • GitHub Check: test-consensus
  • GitHub Check: test (macos-latest)
  • GitHub Check: test
  • GitHub Check: test (windows-latest)
  • GitHub Check: test-consensus-compose
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test (ubuntu-latest)
🔇 Additional comments (32)
lib/common/common/Cargo.toml (1)

19-19: Adding bitvec dependency looks good.

This new dependency is necessary to support the BitSliceExt trait implementation that will be used throughout the codebase for simplifying bit operations.

lib/segment/src/vector_storage/async_raw_scorer.rs (2)

5-5: Importing the new BitSliceExt trait.

Good addition of the trait import needed for the get_bit method.


127-131: Improved deletion checks using get_bit.

This change simplifies the vector deletion checks by using the new get_bit method instead of the more verbose pattern with get, as_deref(), and copied(). The code is now more readable while maintaining the same logic and default behaviors.

lib/segment/src/index/hnsw_index/hnsw.rs (2)

14-14: Importing the new BitSliceExt trait.

Correctly importing the extension trait to enable the get_bit method.


549-549: Simplified deletion check in filter condition.

This change improves readability by replacing a chain of method calls with the more direct get_bit method, maintaining the same behavior of checking if a point is deleted in the filter condition.

lib/segment/src/index/field_index/numeric_index/immutable_numeric_index.rs (3)

7-7: Importing the new BitSliceExt trait.

Correctly importing the extension trait to enable the get_bit method.


119-119: Simplified deletion check in iterator's next method.

This change improves the readability of the code by replacing the chain of method calls with the more direct get_bit method, maintaining the same behavior for checking if an item is deleted.


134-134: Simplified deletion check in iterator's next_back method.

Similar to the change in the next method, this simplifies the deletion check in the next_back method, making the code more readable while preserving the same behavior.

lib/segment/src/vector_storage/dense/simple_dense_vector_storage.rs (2)

9-9: Appropriate trait import for the BitSliceExt extension

The new import uses the underscore pattern (as _) which is ideal for trait extensions that are only used for their methods and not directly referenced elsewhere in the code.


287-287: Improved readability with get_bit method

The new get_bit method provides a cleaner way to retrieve a boolean value from a BitSlice compared to the previous approach, which likely required multiple steps with as_deref() and copied(). This change simplifies the code while maintaining the same functionality.

lib/segment/src/segment/formula_rescore.rs (2)

6-6: Appropriate trait import for BitSliceExt extension

Importing the BitSliceExt trait with the underscore pattern allows its methods to be used on BitSlice instances without bringing the trait name into scope.


42-44: Streamlined bit checking with get_bit method

This change simplifies the code for checking if a point is marked as deleted in a wrapped segment. The new get_bit method provides a more direct way to retrieve the boolean value compared to the previous implementation, making the code cleaner and easier to understand.

lib/segment/src/id_tracker/immutable_id_tracker.rs (2)

9-9: Appropriate trait import for BitSliceExt extension

The BitSliceExt trait is imported with the underscore pattern, which is the recommended approach for using extension traits without bringing the trait name into scope.


118-118: Simplified bit retrieval with get_bit method

The new get_bit method provides a more direct way to check if a point is deleted compared to the previous approach. This change improves code readability while maintaining the same functionality of returning false if the value is not present.

lib/segment/src/vector_storage/dense/mmap_dense_vectors.rs (2)

8-8: Appropriate trait import for BitSliceExt extension

The BitSliceExt trait is imported with the underscore pattern, which is ideal for extension traits that are only used for their methods.


185-185: Simplified bit retrieval with get_bit method

The new get_bit method provides a cleaner way to check if a vector is deleted compared to the previous implementation. This change is consistent with the other files in this PR and improves code readability while maintaining the same functionality.

lib/segment/src/vector_storage/raw_scorer.rs (2)

5-5: LGTM: Adding the BitSliceExt import

This import brings in the necessary trait implementation for the get_bit method used later in the file.


1066-1070: Good simplification with get_bit

The new implementation using get_bit is cleaner and more direct than the previous approach that likely required mapping and dereferencing. The semantics of the function remain unchanged, with proper handling of default values:

  • Default to not deleted if deletion flags failed to grow
  • Default to deleted if the point mapping was removed from ID tracker
lib/segment/src/common/mmap_bitslice_buffered_update_wrapper.rs (2)

5-5: LGTM: Adding the BitSliceExt import

This import brings in the necessary trait implementation for the get_bit method used later in the file.


47-47: Good simplification with get_bit

Replacing self.bitslice.read().get(index).as_deref().copied() with self.bitslice.read().get_bit(index) makes the code more concise while maintaining the same functionality. This is a cleaner way to retrieve a boolean value from a BitSlice.

lib/segment/src/vector_storage/multi_dense/simple_multi_dense_vector_storage.rs (2)

8-8: LGTM: Adding the BitSliceExt import

This import brings in the necessary trait implementation for the get_bit method used later in the file.


426-426: Good simplification with get_bit

Replacing the multi-step approach with a direct get_bit call simplifies the code while maintaining the same behavior. This makes the deletion check more readable and concise.

lib/segment/src/vector_storage/sparse/simple_sparse_vector_storage.rs (2)

7-7: LGTM: Adding the BitSliceExt import

This import brings in the necessary trait implementation for the get_bit method used later in the file.


260-260: Good simplification with get_bit

Replacing the multi-step approach with a direct get_bit call simplifies the code while maintaining the same behavior. This makes the deletion check more readable and concise.

lib/segment/src/id_tracker/id_tracker_base.rs (3)

5-5: Good addition of the BitSliceExt trait import

Adding this import allows the use of the new get_bit method throughout the file, which will simplify bit retrieval operations.


93-96: Improved code clarity with get_bit

The refactoring of this method using the new get_bit method from BitSliceExt simplifies the code by replacing what was likely a chain of get, as_deref, and copied calls with a single, more intuitive method call. This improves readability while maintaining the same functionality.


146-152: Simplified bit retrieval with get_bit

Using the get_bit method here streamlines the bit retrieval from the deleted vector bitslice. The code now directly captures the value and uses a more concise method call, making the logic clearer while preserving the same behavior.

lib/segment/src/index/field_index/bool_index/simple_bool_index.rs (2)

25-25: Added BitSliceExt trait import

This import brings in the new get_bit extension method that will simplify bit retrievals from BitVec instances.


96-97: Improved boolean value retrieval with get_bit

The code now uses the more direct get_bit method instead of the previous approach (likely using get followed by map(|v| *v)). This simplifies the code and makes it more readable while maintaining the same functionality.

lib/common/common/src/ext.rs (3)

1-3: Added necessary imports for BitSliceExt

These imports bring in the required bitvec types for the new extension trait being defined.


19-23: Well-designed BitSliceExt trait with clear documentation

The new trait is well-documented and provides a clear description of its purpose as a convenience wrapper around BitSlice::get. The method signature clearly indicates it returns an Option<bool> which aligns with the PR objective of simplifying boolean value retrieval.


25-30: Concise implementation of get_bit

The implementation elegantly combines as_deref().copied() into a single, reusable method. This abstraction will reduce code duplication and improve readability across the codebase whenever bit values need to be retrieved from a BitSlice.

The implementation correctly handles the conversion from Option<&bool> to Option<bool> by using as_deref().copied(), which is exactly what was needed based on the PR objectives.

✨ 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
🪧 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.
  • @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.

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.

@xzfc xzfc merged commit 6a900dc into dev Mar 12, 2025
17 checks passed
@xzfc xzfc deleted the BitSliceExt-get_bit branch March 12, 2025 20:27
timvisee pushed a commit that referenced this pull request Mar 21, 2025
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