perf(expr): pre-size literal sets - #1812
Conversation
zeroshade
left a comment
There was a problem hiding this comment.
Straightforward and correct change — the map capacity hints are pure upper bounds (duplicates collapsing after the To(boundType) cast in createBoundSetPredicate just means slight over-allocation, never incorrect behavior). Switching typedSet in exprs.go:953 from the Set[Literal] interface returned by newLiteralSet() to the concrete literalSet is behaviorally equivalent: all method sets are value receivers, newBoundSetPredicate still receives it as Set[Literal], and the other.(literalSet) assertion in literalSet.Equals still matches since the dynamic type is unchanged. Verified the build, full package tests, and both new benchmarks pass on the PR head; the allocation numbers roughly match the description's claims. Benchmarks are a nice addition for future regression tracking.
What
INsets.Why
Large
INpredicates currently build maps from an empty capacity. The maps grow and rehash while the literals are inserted, and binding builds a second set with the same issue.Performance
For 8,192
INvalues on an Apple M1 Pro, using three 250 ms benchmark runs:The exact CPU result depends on the literal count and workload. The allocation reduction is the main benefit.
Tests
go test .go test -race .go test ./...