Repository navigation
Conversation
…ement
The map-based paths (findUniquesByLarge/findDuplicatesByLarge) called the
iteratee twice per element - once to classify keys, once to emit results -
while the small-scan paths called it exactly once. This made the callback
count depend on whether the collection crossed findSmallThreshold, and did
redundant work on the common large path. Precompute the keys once, so the
iteratee is invoked exactly once per element regardless of collection size,
matching findUniquesBySmall/findDuplicatesBySmall and the public doc
("invoked for each element").
This branch has not been deployed
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.
Describe your changes
FindUniquesByandFindDuplicatesBydispatch onlen(collection) <= findSmallThreshold:...Smallpaths precompute the derived keys and invoke the iteratee exactly once per element;...Largepaths invoked the iteratee twice per element (once in the classification pass, once in the emission pass).As a result the number of iteratee calls jumps discontinuously at the size threshold, and the large path does redundant work. The doc for the exported helpers states the iteratee "is invoked for each element", and
findUniquesBySmalleven says it matches "the single-invocation contract of the map-based path" — which the map path did not honor.This change precomputes the keys once in
findUniquesByLargeandfindDuplicatesByLarge, so the iteratee is invoked exactly once per element regardless of collection size. Output is unchanged. The...ByErrvariants are intentionally left as-is (they have no small/large split and their tests rely on second-pass error behavior).Repro on current master (
n= collection size):Related issues
None filed; found by inspection. Note this is the slice API in
find.go. The same class of double-consumption in the separateit(iterator) package is handled by #1026 / #1032; those do not touchfind.go, so there is no overlap with this PR.Checklist
TestFindUniquesBy_singleInvocationandTestFindDuplicatesBy_singleInvocation, asserting exactly-once on both sides of the boundary)Tests
Prepared with AI assistance and manually reviewed/verified locally.