Refactor PPR top-k selection helper - #723
Open
mkolodner-sc wants to merge 2 commits into
Open
Conversation
mkolodner-sc
force-pushed
the
mkolodner-sc/ppr-selector-helper
branch
5 times, most recently
from
July 28, 2026 11:16
b5b0bb0 to
3e093f5
Compare
mkolodner-sc
force-pushed
the
mkolodner-sc/ppr-selector-helper
branch
from
July 28, 2026 11:18
3e093f5 to
930569f
Compare
kmontemayor2-sc
approved these changes
Jul 29, 2026
kmontemayor2-sc
left a comment
Collaborator
There was a problem hiding this comment.
Thanks Matt! LGTM provided we are ok with this behavior change
https://github.com/Snapchat/GiGL/pull/723/changes#r3675350401
yliu2-sc
approved these changes
Jul 29, 2026
mkolodner-sc
marked this pull request as ready for review
July 30, 2026 07:46
mkolodner-sc
requested review from
nshah-sc,
svij-sc,
xgao4-sc and
zfan3-sc
as code owners
July 30, 2026 07:46
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.
Description
This PR refactors PPR extraction by moving the existing inline finalized-PPR selection and residual top-up logic into smaller C++ helpers.
The extraction behavior is intended to stay the same, but the implementation is now split into reusable pieces:
selectFinalizedPPRPairs: selects finalized PPR candidates by raw PPR scoreaddResidualMassToPPRPairs: adds residual mass to selected finalized PPR candidates when residual top-up is enabledappendResidualTopUpPairs: appends residual candidates into remaining sequence slotsThese helpers replace logic that previously lived directly inside
extractTopKWithResidualTopUp. The untyped extraction path still owns final output assembly and sorting, but the lower-level pieces can now be reused by the typed-channel PPR extraction work in the stacked PR.No functional change is intended.
Performance
This refactor should be mostly performance-neutral, if not slightly faster.
The main algorithmic work is the same as before: scan finalized PPR scores, select finalized top-k candidates, optionally scan residuals for top-up candidates, add residual mass to selected finalized candidates, append top-up rows, and sort the emitted rows. The PR mostly moves those existing steps into named helpers.
One small implementation detail changes: finalized PPR selection now uses
nth_elementfollowed by a final sort of the selected output rows, instead of relying onpartial_sortin the non-top-up path. This avoids ordering intermediate candidates before we know the final emitted set. The asymptotic behavior is unchanged for the final output, but this can save some unnecessary ordering work, so any runtime difference should skew neutral-to-slightly-faster rather than slower.Testing
make -C gigl-core format_cppgit diff --checkuv run ty check .github/scripts examples gigl tests snapchat scriptsmake -C gigl-core unit_test_cpp