Knetic / govaluate

Arbitrary expression evaluation for golang
MIT License
3.75k stars 503 forks source link

Optimize IN comparion by using a map instead of slice when possible #189

Open Richtermeister opened 12 months ago

Richtermeister commented 12 months ago

This PR aims to optimize IN expressions with static clauses. The example benchmark a in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) included is rather small but illustrates the point, especially since allocations grow in proportion to number of entries involved. In production we have expressions against 40k+ IN entries, which massively benefits from this optimization.

goos: darwin
goarch: amd64
pkg: github.com/govaluate
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkIn

Before:
BenchmarkIn-16       1050931          1106 ns/op        1056 B/op         17 allocs/op

After:
BenchmarkIn-16       4521502           269.5 ns/op       360 B/op          4 allocs/op