-
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
Tweaks to reduce number of allocations in regal lint
hot path
#7172
Conversation
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.
These are all great changes, thank you. I suppose I'd rather change the existing ast methods BooleanTerm
and IntNumberTerm
than add new functions, but it's not a strong opinion, I'd be curious whah @ash-styra and @johanfylling think about that.
Ran with benchstat, just for completeness...
|
@srenatus existing functions are sometimes used like this: Line 286 in c47b8c1
i.e mutating the pointer returned. If we want to have a single function to create bool/int terms, we'd have to at least identify all uses where mutation can happen after the pointer is returned. Having separate functions for cached values seemed like at least some way to try and communicate intent. |
Ah right, these are terms! Yeah that makes sense, many of them will have a location. OK I'm convinced. I'm little on the fence about the "cached" terminology... a cache somehow carries the connotation that you can have a hit or a miss, or that something is cached for a while and then isn't. Would "Static" seem like a valid alternative? "Interned"? 🤔 |
Interned sounds good to me! I'll make that change. |
9080067
to
b7343d5
Compare
Concluding my quest to reduce the number of allocations in the hot path for `regal lint` for this time around. This PR mainly does so by reusing pointers to boolean and integer terms where these are determined not to be mutated later. The result is another ~4 million allocations reduced when linting Regal against its own bundle. These improvements should however help reduce allocations in pretty much any evaluation. **opa main** ``` BenchmarkRegalLintingItself-10 1 3195257584 ns/op 6496097784 B/op 120108808 allocs/op ``` **PR branch** ``` BenchmarkRegalLintingItself-10 1 3132126333 ns/op 6376318224 B/op 116163318 allocs/op ``` Signed-off-by: Anders Eknert <[email protected]>
b7343d5
to
9105571
Compare
@ash-styra @johanfylling could you have a look, please? 😎 |
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.
These changes look good. Few comments 👇
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.
Let's get this merged! 🥳
Concluding my quest to reduce the number of allocations in the hot path for
regal lint
for this time around. This PR mainly does so by reusing pointers to boolean and integer terms where these are determined not to be mutated later.The result is another ~4 million allocations reduced when linting Regal against its own bundle. These improvements should however help reduce allocations in pretty much any evaluation.
opa main
PR branch