Skip to content

Conversation

agourlay
Copy link
Member

@agourlay agourlay commented Jul 3, 2025

This has_id implementation is is a prime candidate for AHashSet because it tests the membership in a set of u32.

With some naive benchmarking, I get a 10% latency improvements on large distance matrix requests.

e.g.

POST /collections/benchmark/points/search/matrix/pairs
{
  "sample": 500,
  "limit": 1000
}

@agourlay agourlay requested a review from timvisee July 3, 2025 14:01
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

📝 Walkthrough

Walkthrough

This change updates the condition_converter method in StructPayloadIndex by replacing the use of the standard library's HashSet with AHashSet from the ahash crate for storing internal IDs in the Condition::HasId and Condition::CustomIdChecker match arms. The import for AHashSet replaces the standard HashSet import. The logic for filtering external IDs and checking point ID membership remains unchanged. No changes were made to the declarations or signatures of exported or public entities.

Possibly related PRs

Suggested reviewers

  • generall
  • timvisee

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Clippy (1.86.0)
Updating git repository `https://github.com/qdrant/tar-rs`

error: failed to load source for dependency tar

Caused by:
Unable to update https://github.com/qdrant/tar-rs?branch=main#856dbd09

Caused by:
failed to create directory /usr/local/git/db/tar-rs-f03560d008573c0e

Caused by:
Permission denied (os error 13)


📜 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 1f94d4d and b589a23.

📒 Files selected for processing (1)
  • lib/segment/src/index/query_optimization/condition_converter.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/segment/src/index/query_optimization/condition_converter.rs
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: rust-tests (ubuntu-latest)
  • GitHub Check: rust-tests-no-rocksdb (ubuntu-latest)
  • GitHub Check: rust-tests (macos-latest)
  • GitHub Check: rust-tests (windows-latest)
  • GitHub Check: test-snapshot-operations-s3-minio
  • GitHub Check: test-low-resources
  • GitHub Check: test-shard-snapshot-api-s3-minio
  • GitHub Check: test-consistency
  • GitHub Check: integration-tests-consensus
  • GitHub Check: storage-compat-test
  • GitHub Check: integration-tests
  • GitHub Check: lint
  • GitHub Check: test-consensus-compose
  • GitHub Check: Basic TLS/HTTPS tests
✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

Copy link
Contributor

@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 (1)
lib/segment/src/index/query_optimization/condition_converter.rs (1)

186-186: Consider consistency: Why not optimize CustomIdChecker too?

The CustomIdChecker condition also uses HashSet for storing internal IDs and performing membership checks, similar to the has_id condition. For consistency and potential performance gains, consider using AHashSet here as well.

-                let segment_ids: HashSet<_> = id_tracker
+                let segment_ids: AHashSet<_> = id_tracker

If there's a specific reason to keep HashSet for CustomIdChecker (e.g., different usage patterns or performance characteristics), please clarify in the code comments.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9e036ea and 1f94d4d.

📒 Files selected for processing (1)
  • lib/segment/src/index/query_optimization/condition_converter.rs (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: JojiiOfficial
PR: qdrant/qdrant#5951
File: lib/api/src/grpc/qdrant.rs:6493-6496
Timestamp: 2025-03-12T09:25:16.340Z
Learning: The `payload_index_io_read` field in `HardwareUsage` was introduced in PR #5951 and is safe to modify as it was not used in production before this PR.
Learnt from: coszio
PR: qdrant/qdrant#6565
File: lib/posting_list/src/builder.rs:63-67
Timestamp: 2025-05-26T14:47:23.505Z
Learning: In the posting_list crate's PostingChunk struct, avoid adding extra fields like storing computed chunk_bits to prevent struct bloat and maintain mmap compatibility. The bit calculations from offsets are inexpensive compared to the memory and compatibility benefits of keeping the struct minimal.
lib/segment/src/index/query_optimization/condition_converter.rs (1)
Learnt from: IvanPleshkov
PR: qdrant/qdrant#6728
File: lib/quantization/src/encoded_vectors_binary.rs:810-810
Timestamp: 2025-07-02T17:10:13.847Z
Learning: In the Qdrant quantization codebase, hardware counters (hw_counter.cpu_counter()) are used to measure vector data access from storage, not computational cost. With asymmetric binary quantization where query vectors can be longer than storage vectors, the counter should still track vector_data.len() to maintain consistent measurement of storage access patterns, not query processing overhead.
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Basic TLS/HTTPS tests
  • GitHub Check: test-low-resources
  • GitHub Check: test-shard-snapshot-api-s3-minio
  • GitHub Check: test-consistency
  • GitHub Check: test-consensus-compose
  • GitHub Check: test-snapshot-operations-s3-minio
  • GitHub Check: lint
  • GitHub Check: integration-tests-consensus
  • GitHub Check: integration-tests
  • GitHub Check: storage-compat-test
  • GitHub Check: rust-tests (windows-latest)
  • GitHub Check: rust-tests-no-rocksdb (ubuntu-latest)
  • GitHub Check: rust-tests (macos-latest)
  • GitHub Check: rust-tests (ubuntu-latest)
🔇 Additional comments (2)
lib/segment/src/index/query_optimization/condition_converter.rs (2)

3-3: Good optimization choice for performance-critical path.

Adding AHashSet import to optimize membership checking operations. AHash is generally faster than the default hasher for this use case.


113-113: Excellent optimization for has_id membership checking.

Replacing HashSet with AHashSet for the segment_ids collection is a smart optimization. Since this is used for membership checking with u32 internal IDs, the faster AHash algorithm should provide measurable performance improvements, especially for large ID sets as mentioned in the PR description.

@agourlay agourlay merged commit a5bce06 into dev Jul 3, 2025
18 checks passed
@agourlay agourlay deleted the optimiza-has-id-ahash branch July 3, 2025 14:39
@timvisee
Copy link
Member

timvisee commented Jul 3, 2025

I get a 10% latency improvements on large distance matrix requests.

That is huge! Nice find.

generall pushed a commit that referenced this pull request Jul 17, 2025
* Optimize has_id with ahash

* apply same pattern to CustomIdChecker
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.

3 participants