Skip to content

Address inefficiency related to creating and returning tag values as absl::flat_hash_set by value during predicate evaluation - #1296

Open
yairgott wants to merge 2 commits into
mainfrom
tag_avoid_return_by_value
Open

Address inefficiency related to creating and returning tag values as absl::flat_hash_set by value during predicate evaluation#1296
yairgott wants to merge 2 commits into
mainfrom
tag_avoid_return_by_value

Conversation

@yairgott

@yairgott yairgott commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

During vector search pre-filtering, PrefilterEvaluator::EvaluateTags invoked Tag::GetValue() for every candidate document key.

Tag::GetValue() dynamically constructed and returned a heap-allocated absl::flat_hash_set<absl::string_view> via ParseRecordTags(). For queries evaluating thousands of candidate keys:

  1. Heap Allocation Overhead: Every candidate key evaluation triggered dynamic heap allocations and deallocations to populate the hash set.
  2. Container Return-by-Value: Returning std::optional<absl::flat_hash_set> by value added copy/move and destructor overhead per candidate check.
  3. No Early Exit: ParseRecordTags() fully parsed and inserted all tags into the set before predicate matching began, even if the first tag matched.

Solution

  1. Zero-Allocation Raw Tag Access: Added Tag::GetRawTagString() to return an absl::string_view of the key's stored raw tag string without container instantiation or heap allocation.
  2. On-the-Fly Raw Tag Evaluation: Added an overload TagPredicate::Evaluate(absl::string_view raw_tag_string, char separator, bool case_sensitive) that lazily splits the raw string and exits early as soon as a tag matches.
  3. Deduplicated Match Logic: Extracted tag comparison logic (wildcards, prefix matching, case sensitivity) into a private helper TagPredicate::MatchesSingleTag() to share implementation between set-based and raw-string-based evaluation overloads.
  4. Prefilter Integration: Updated PrefilterEvaluator::EvaluateTags() to leverage the zero-allocation raw tag evaluation path.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5d1fb95a-7796-47ac-bdb9-7bf376946b2b

📥 Commits

Reviewing files that changed from the base of the PR and between 7408a37 and 0e65281.

📒 Files selected for processing (2)
  • .devcontainer/run_in_docker.sh
  • src/query/predicate.cc

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The change exposes raw tag values, evaluates separator-aware predicates in vector prefilters, adds a devcontainer command runner, and updates CI validation behavior.

Changes

Raw tag matching

Layer / File(s) Summary
Raw tag value API
src/indexes/tag.h, src/indexes/tag.cc, testing/tag_index_test.cc
Tag::GetRawTagString returns tracked raw tag strings or std::nullopt. Tests cover retrieval and missing keys.
Raw predicate evaluation
src/query/predicate.h, src/query/predicate.cc, testing/tag_index_test.cc
TagPredicate matches exact and trailing-wildcard values with configurable case sensitivity. Raw strings are split by the configured separator, trimmed, and evaluated individually.
Prefilter integration
src/indexes/vector_base.cc, testing/tag_index_test.cc
EvaluateTags retrieves raw values and applies index separator and case-sensitivity settings. Tests cover alternate separators, unknown keys, prefixes, and multi-tag queries.

Devcontainer runtime

Layer / File(s) Summary
Devcontainer setup
.devcontainer/run_in_docker.sh
The runner detects the workspace and user, selects command and terminal settings, configures cleanup, and prepares images, mounts, and ccache.
Devcontainer execution
.devcontainer/run_in_docker.sh
The runner reuses matching devcontainers or starts new containers with synchronized Git and SSH configuration, workspace mounts, user identity, networking, capabilities, and environment variables.

CI validation updates

Layer / File(s) Summary
CI validation behavior
.github/workflows/clang_tidy_format.yml, ci/build_ubuntu.sh
Clang-tidy runs for modified .cc files after configuration. Core-pattern setup no longer stops the Ubuntu build when the system write fails.

Sequence Diagram(s)

sequenceDiagram
  participant PrefilterEvaluator
  participant Tag
  participant TagPredicate
  PrefilterEvaluator->>Tag: GetRawTagString(key)
  Tag-->>PrefilterEvaluator: Raw tag string or nullopt
  PrefilterEvaluator->>TagPredicate: Evaluate(raw tag string, separator, case sensitivity)
  TagPredicate-->>PrefilterEvaluator: Evaluation result
Loading

Suggested reviewers: karthiksubbarao, allenss-amazon, mnunberg1, murphyjacob4

Merge Risk: 🔵 Low · up to 0e652

The development-container setup reuses a fixed temporary dependency directory, which can cause stale data or collisions between runs. The PR is otherwise mergeable, with owner awareness needed to make the export directory unique per run.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: avoiding inefficient construction and return-by-value of tag value sets during predicate evaluation.
Description check ✅ Passed The description directly explains the allocation and return-by-value inefficiency and describes the raw-string evaluation changes that address it.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

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

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown

Greptile Summary

This change evaluates vector TAG prefilters directly from stored raw tag strings, avoiding temporary tag-set construction while preserving matching behavior.

Confidence Score: 5/5

No blocking failure remains.

The exercised TAG matching paths produced the same results before and after the change.

T-Rex T-Rex Logs

What T-Rex did

  • Ran a focused before-and-after TAG predicate harness that exercises whitespace, empty and duplicate tokens, case-sensitive and case-insensitive equality, custom separators, prefix wildcards, multi-tag queries, substring rejection, and empty input.
  • Compared the parsed-set and raw-string TAG predicate paths and confirmed both passed all nine test cases with identical results.
  • Attempted to configure and run native repository tests with the build script, but GoogleTest could not run due to a missing CMake tool.
  • Validated parity between the before and after paths by passing all nine cases in both directions, with outputs identical apart from the recorded command mode.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (11): Last reviewed commit: "Merge branch 'main' into tag_avoid_retur..." | Re-trigger Greptile

@yairgott
yairgott force-pushed the tag_avoid_return_by_value branch from 2115810 to c990f6b Compare August 12, 2026 02:15
@yairgott yairgott changed the title Address inefficiency by avoiding returning tag values by value during predicate evaluation Address inefficiency related to returning tag values as absl::flat_hash_set by value during predicate evaluation Aug 12, 2026
@yairgott yairgott changed the title Address inefficiency related to returning tag values as absl::flat_hash_set by value during predicate evaluation Address inefficiency related to creating and returning tag values as absl::flat_hash_set by value during predicate evaluation Aug 12, 2026
@yairgott
yairgott force-pushed the tag_avoid_return_by_value branch 2 times, most recently from 5e46f16 to cdb7014 Compare August 12, 2026 03:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.devcontainer/run_in_docker.sh:
- Around line 32-39: Replace the fixed sleep in the SSH agent setup around
socket_proxy.py with a bounded readiness loop that waits for $PROXY_SOCKET to
appear, checks whether PROXY_PID has exited, and fails with a clear error if the
proxy exits or the socket is not created before the timeout; export
SSH_AUTH_SOCK only after successful readiness verification.
- Around line 84-90: Restrict SSH exposure in .devcontainer/run_in_docker.sh: at
lines 84-90, update the .ssh copy logic to transfer only required non-secret
files such as config and known_hosts, never private keys; at lines 122-126,
remove the full .ssh bind mount and mount only explicitly selected non-secret
configuration files if needed. Preserve SSH-agent proxy access for signing.
- Around line 108-114: Make the Docker image build step in the script fail fast
by enabling appropriate shell error handling or explicitly checking the docker
build status before proceeding. Ensure docker run is skipped when the build
fails, preventing an existing valkey-search-dev image from being used.
- Around line 43-58: Update the dependency extraction flow around CONTAINER_ID
to create a unique per-run temporary directory with mktemp -d, use that
directory as the docker cp destination, and substitute the same path when
rewriting compile_commands.json. Avoid the fixed /tmp/valkey-search-deps path so
existing directories cannot cause nested copies or stale references.

In @.devcontainer/socket_proxy.py:
- Around line 15-25: Update the proxy’s socket, file, and cleanup exception
handling to catch only expected OSError failures instead of broad Exception
clauses. Ensure initialization and accept() failures are reported before
exiting, and route those diagnostics through a visible channel rather than the
launcher’s /dev/null output redirection.

In @.github/workflows/clang_tidy_format.yml:
- Line 97: Update the clang-tidy command in the workflow’s inner bash invocation
to enable pipefail, or otherwise explicitly preserve clang-tidy’s exit status
through the tail pipeline. Ensure the workflow fails whenever clang-tidy exits
non-zero while retaining the existing output filtering.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c19e3c8b-e794-4b6e-89d4-f702ca51c150

📥 Commits

Reviewing files that changed from the base of the PR and between c990f6b and cdb7014.

📒 Files selected for processing (5)
  • .devcontainer/run_in_docker.sh
  • .devcontainer/socket_proxy.py
  • .github/workflows/clang_tidy_format.yml
  • src/indexes/tag.cc
  • src/query/predicate.cc
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/indexes/tag.cc
  • src/query/predicate.cc

Comment thread .devcontainer/run_in_docker.sh Outdated
Comment thread .devcontainer/run_in_docker.sh
Comment thread .devcontainer/run_in_docker.sh Outdated
Comment thread .devcontainer/run_in_docker.sh Outdated
Comment thread .devcontainer/socket_proxy.py Outdated
Comment thread .github/workflows/clang_tidy_format.yml Outdated
@yairgott
yairgott force-pushed the tag_avoid_return_by_value branch 7 times, most recently from 9250929 to 7408a37 Compare August 12, 2026 15:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.devcontainer/run_in_docker.sh:
- Around line 127-155: The fresh-container execution path around the bash and
command branches must assign a unique CONTAINER_ID before starting Docker, use
that name without --rm, and ensure cleanup copies /opt/valkey-search-deps before
removing the container. Update cleanup to remove only containers created by this
runner while preserving compile_commands.json rewriting and existing container
behavior.
- Around line 15-19: Update the command setup in the run script to preserve
argument boundaries by storing the incoming arguments in an array such as
COMMAND, defaulting that array to bash when no arguments are provided. Replace
every CMD-based bash -c execution with direct "${COMMAND[@]}" execution, and do
not add implicit shell evaluation.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cb8f6c86-779c-487d-81a2-feab14a683e1

📥 Commits

Reviewing files that changed from the base of the PR and between cdb7014 and 7408a37.

📒 Files selected for processing (7)
  • .devcontainer/run_in_docker.sh
  • .github/workflows/clang_tidy_format.yml
  • ci/build_ubuntu.sh
  • src/indexes/tag.cc
  • src/indexes/tag.h
  • src/indexes/vector_base.cc
  • testing/tag_index_test.cc
🚧 Files skipped from review as they are similar to previous changes (3)
  • .github/workflows/clang_tidy_format.yml
  • src/indexes/tag.h
  • src/indexes/vector_base.cc

Comment thread .devcontainer/run_in_docker.sh
Comment thread .devcontainer/run_in_docker.sh Outdated
… predicate evaluation

Signed-off-by: Yair Gottdenker <yairg@google.com>
@yairgott
yairgott force-pushed the tag_avoid_return_by_value branch from 7408a37 to 425bfe3 Compare August 12, 2026 15:53
@Aksha1812

Copy link
Copy Markdown
Collaborator

/reviewer mnunberg1

@Aksha1812

Copy link
Copy Markdown
Collaborator

/reviewer KarthikSubbarao

@Aksha1812

Copy link
Copy Markdown
Collaborator

Reviewers for this PR

  • First Pass Reviewer: @mnunberg1 — Please do your best to do a detailed review on the PR and get a response on your feedback. Once the first pass is done, notify the maintainer assigned to this PR to follow up on the final review and getting the PR merged. You can reach out to the people owning the relevant code paths for more help on the review.
  • Maintainer Reviewer: @KarthikSubbarao — Once the first review is done, please follow up with a final review and help to merge the change in.

@github-actions
github-actions Bot requested a review from mnunberg1 August 13, 2026 00:32
@mnunberg1

Copy link
Copy Markdown
Collaborator

This should be split into different commits, I'm two files deep and there's nothing related to the actual title of the PR

@BCathcart BCathcart added the 1.3.0 Issues to be included in v1.3.0 label Aug 24, 2026
@Frank-Gu-81

Copy link
Copy Markdown
Collaborator

Hi @yairgott 👋 — this is tracked as a P2 for valkey-search 1.3. P2s aren't RC1 blockers, but we'd love to land them for GA.

First-pass reviewer: @mnunberg1 — if your first-pass review is already done, please ignore this message; otherwise, please prioritize getting this PR reviewed.

Second-pass reviewer: @KarthikSubbarao — please take a look/followup with the final review and merge once everything looks good.

If it's close to ready, getting it merged soon keeps it comfortably ahead of GA. Board: #1346. Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.3.0 Issues to be included in v1.3.0

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants