Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Richtermeister
Copy link

@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 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