-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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.Array should cache groundness bit to avoid unnecessary computation #3679
Comments
This is a little hairier with arrays compared to sets: when slicing an array, the elements are still shared. So
Still worth improving, of course. 👍 |
Looking further into this, the Lines 2709 to 2731 in 8fc2ba1
we'll get a Number term for the index here, and feed that into Lines 2777 to 2782 in 8fc2ba1
without any checks for groundness. |
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>
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 #3679. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
The ast.Array structure does not memoize groundness. As a result, checks for groundness have to recompute for all elements which can be expensive for large arrays.
Related: 00be8a2
The text was updated successfully, but these errors were encountered: