Skip to content

perf(builtin): index numbers in uniq - #1027

Merged
antonmedv merged 3 commits into
masterfrom
uniq-numeric-index
Nov 25, 2026
Merged

antonmedv merged 3 commits into
masterfrom
uniq-numeric-index

Conversation

@antonmedv

Copy link
Copy Markdown
Member

uniq compares 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.Equal exactly:

  • integers equal each other via int(x), so they are keyed by int
  • integers equal floats via float64(x), so integers are also keyed by float64 for float lookups, separately from floats
  • everything else (nil, bool, durations, named types, nested values) still uses a linear scan

So 2^53 and 2^53+1 stay distinct even though both equal float64(2^53), uint64(MaxUint64) still equals -1 and 2^64, NaN is never deduplicated, and -0 == 0. Sets below 16 unique values still scan linearly, as before.

TestBuiltin_UniqNumbers checks the result against a plain runtime.Equal scan over shuffled mixes of these edge cases.

expression before after
uniq(1..20000) 675ms 3ms
uniq(1..999999) hours ~200ms

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.
@antonmedv
antonmedv merged commit 52612b9 into master Nov 25, 2026
22 checks passed
@antonmedv
antonmedv deleted the uniq-numeric-index branch November 25, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant