Deduplicate in_network_ids before VF lookup - #88
Open
joshs1017dev wants to merge 1 commit into
Open
Conversation
in_network_ids is passed to the VF client without deduplication, while oon_ids is deduped four lines below. retweeted_tweet_id is pushed for every candidate that has one, so the same ID repeats once per retweet of a given post — most often when that post is going viral. Neither VfClient implementation dedupes its input: StratoVfClient builds one call per element, and XaiVfClient chunks by XAI_VF_MAX_BATCH_SIZE, so duplicates consume batch slots and can force an extra round trip. Not a correctness issue — results collapse into a HashMap keyed by tweet ID — but redundant work on the For You serving path. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
VFCandidateHydrator::hydratebuilds two ID lists, but only one of them is deduplicated:in_network_idsis never deduped, so duplicate tweet IDs are sent to the VF client onevery home-timeline request.
Why duplicates occur in practice
retweeted_tweet_idis pushed toin_network_idsunconditionally for every candidatethat has one — independent of the candidate's own
in_networkflag:So the list contains a duplicate whenever:
retweeted_tweet_idis pushedonce per retweet. This is most likely exactly when a post is going viral, i.e. when
candidate sets are largest.
pushed once as
candidate.tweet_idand again asretweeted_tweet_id.Why it costs something
Neither
VfClientimplementation deduplicates its input:StratoVfClientbuilds one Strato call per element oftweet_idsand dispatchesthem together, so each duplicate is a redundant subcall in the batch.
XaiVfClientsplits the input withtweet_ids.chunks(XAI_VF_MAX_BATCH_SIZE), soduplicates consume batch slots and can push the request into an additional chunk — an
extra round trip that carries no new information.
This is not a correctness issue: results are collected into a
HashMapkeyed by tweet ID,so duplicates collapse on the way back. It is purely wasted work on the For You serving
path, and it scales with how popular the retweeted posts in the candidate set are.
Precedent in the codebase
Both nearby cases already dedupe before dispatch:
oon_ids, four lines below, in this same function.post_idsinvf_following_candidate_hydrator.rs, which dedupes its single list.This change simply makes
in_network_idsconsistent with both.The change
Two lines, mirroring the adjacent
oon_idshandling.Testing
I was not able to compile or run tests against this: the published repository has no
workspace
Cargo.tomlforhome-mixer, so the crate isn't buildable standalone from theopen-source export. The change is deliberately limited to the same two-call pattern used
on the adjacent list to keep it verifiable by inspection.
Happy to add a test with a recording
VfClientmock asserting no duplicate IDs reachget_resultif that's useful —ScoredPostsQueryderivesDefault, so the fixture isstraightforward, but I'd rather not add a test I can't run.