Repository navigation
[Store] Avoid quadratic deduplication of local-first candidates #5528
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
Open
importcpp
wants to merge
1
commit into
kvcache-ai:main
Choose a base branch
from
importcpp:codex/perf-local-first-dedup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+165
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use a request-local
std::unordered_set<std::string_view>here, while keepingpreferred_segmentsas the owning, insertion-ordered vector?The current implementation is safe, but the temporary set owns another copy of every unique name. For names beyond SSO, this adds character-buffer allocations and frees on top of the hash-node allocations, all inside the segment shared-lock scope.
This should not be a mechanical type replacement: views seeded from
preferred_segmentscan dangle when subsequentpush_backcalls reallocate that vector, especially for SSO strings. One bounded-scope alternative is:With this scope, the existing preference strings cannot move during insertion,
host_ordered_segmentsremains unmodified, andseenis destroyed before either backing vector. Preference order and name-based deduplication stay unchanged.This could reduce temporary bytes/copies and long-name allocations without changing placement policy. It still allocates hash nodes and hashes all names, so it should not be assumed to eliminate the small-pool regression. Could the existing A/B harness and allocation census compare this variant for both small pools and large short-/long-name pools?
This is an optimization suggestion, not a correctness finding against the current owning-string implementation.