Repository navigation
perf(builtin): index numbers in uniq - #1027
Merged
Merged
Conversation
Extend the string index from #1007 to integer and float values, keyed the same way runtime.Equal compares them. uniq(1..999999) drops from hours to ~200ms.
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.
uniqcompares each value against every unique value seen so far, so it is quadratic for anything but strings (#1007 added a string index). This extends the index to integer and float values.Keys follow
runtime.Equalexactly:int(x), so they are keyed byintfloat64(x), so integers are also keyed byfloat64for float lookups, separately from floatsSo
2^53and2^53+1stay distinct even though both equalfloat64(2^53),uint64(MaxUint64)still equals-1and2^64, NaN is never deduplicated, and-0 == 0. Sets below 16 unique values still scan linearly, as before.TestBuiltin_UniqNumberschecks the result against a plainruntime.Equalscan over shuffled mixes of these edge cases.uniq(1..20000)uniq(1..999999)