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
ast+topdown: cache array groundness #4151
ast+topdown: cache array groundness #4151
Conversation
module := `package test | ||
fixture := data.fixture | ||
main { x := fixture }` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to make this benchmark oddly specific to see an effect:
name old time/op new time/op delta
ArrayPlugging/10-16 14.4µs ± 1% 14.3µs ± 3% ~ (p=0.690 n=5+5)
ArrayPlugging/100-16 22.7µs ±11% 21.0µs ±14% ~ (p=0.095 n=5+5)
ArrayPlugging/1000-16 95.4µs ± 8% 77.8µs ± 5% -18.41% (p=0.008 n=5+5)
ArrayPlugging/10000-16 852µs ± 4% 685µs ± 2% -19.55% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
ArrayPlugging/10-16 9.83kB ± 0% 9.71kB ± 0% -1.22% (p=0.008 n=5+5)
ArrayPlugging/100-16 15.1kB ± 0% 14.1kB ± 0% -6.22% (p=0.008 n=5+5)
ArrayPlugging/1000-16 65.7kB ± 0% 57.5kB ± 0% -12.54% (p=0.008 n=5+5)
ArrayPlugging/10000-16 574kB ± 0% 492kB ± 0% -14.30% (p=0.008 n=5+5)
name old allocs/op new allocs/op delta
ArrayPlugging/10-16 191 ± 0% 188 ± 0% -1.57% (p=0.008 n=5+5)
ArrayPlugging/100-16 371 ± 0% 368 ± 0% -0.81% (p=0.008 n=5+5)
ArrayPlugging/1000-16 2.17k ± 0% 2.17k ± 0% -0.14% (p=0.008 n=5+5)
ArrayPlugging/10000-16 20.2k ± 0% 20.2k ± 0% -0.01% (p=0.008 n=5+5)
@@ -104,6 +107,9 @@ func (u *bindings) plugNamespaced(a *ast.Term, caller *bindings) *ast.Term { | |||
}) | |||
return &cpy | |||
case ast.Set: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the other three shortcuts added here, I have not yet thought about when they'd happen -- they do seem to make sense in a pattern-match kind of way 🙃
bcc3f0e
to
5bf956c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The TODOs on the bindings look fine to me.
OK great. I'll update this and get it merged. |
I had been believing that we couldn't do this, since many methods allow changing an array's elements in ways that would invalidate the cached groundness bit. However, if we don't do that, we're OK. To get the tests to pass, the walk builtin implementation had implicitly depended on array plugging returning a copy; that's now made explicit. In topdown/bindings, this adds a few more shortcuts where applicable (array/set). Previously, only objects had a ground?- shortcutin plugging and namespacing vars. Fixes open-policy-agent#3679. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
5bf956c
to
1842468
Compare
I had been believing that we couldn't do this, since many methods allow changing an array's elements in ways that would invalidate the cached groundness bit. However, if we don't do that, we're OK.
To get the tests to pass, the
walk
builtin implementation had implicitly depended on array plugging returning a copy; that's now made explicit.Fixes #3679.