Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

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

Open
Richtermeister wants to merge 3 commits into
Knetic:masterfrom
TheDMSGroup:optimize-in
Open

Optimize IN comparion by using a map instead of slice when possible#189
Richtermeister wants to merge 3 commits into
Knetic:masterfrom
TheDMSGroup:optimize-in

Conversation

@Richtermeister
Copy link
Copy Markdown

@Richtermeister Richtermeister commented Nov 16, 2023

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant