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

Improve storage lookup performance #7336

Merged
merged 2 commits into from
Feb 5, 2025

Conversation

anderseknert
Copy link
Member

Some code I had left from the weekend, where I looked into the cost of querying the store during eval, and if that could be improved. The code here is mostly benchmarks that I found useful for that purpose, but also includes a few optimizations of code that is on the hot path for these lookups and as such has a high impact — as the benchmarks demonstrate.

The small change in eval.go is the first use of the new feature of object.Map added some days ago, where a map function returning a nil key means skipping that key/value pair.

Copy link
Contributor

@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return &storage.Error{
Code: storage.NotFoundErr,
Message: message,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a performance optimization?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, saw the benchtest 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's quite insidious how much Sprintf can cost even in simple cases!

sb.Grow(l)
for i := range p {
sb.WriteByte('/')
sb.WriteString(url.PathEscape(p[i]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this causes escaping, I suppose the only ill effect is that the above sb.Grow(l) wasn't enough and sb needs to grow further?

Since you're interested in performance in this PR, I assume you've confirmed this is better or equal in performance compared to the old method for the general/common case. How about the worst case, where sb needs to grow further (maybe more than once)?

Some code I had left from the weekend, where I looked into
the cost of querying the store during eval, and if that could
be improved. The code here is mostly benchmarks that I found
useful for that purpose, but also includes a few optimizations
of code that is on the hot path for these lookups and as such
has a high impact — as the benchmarks demonstrate.

The small change in eval.go is the first use of the new feature
of object.Map added some days ago, where a map function returning
a nil key means skipping that key/value pair.

Signed-off-by: Anders Eknert <[email protected]>
@anderseknert anderseknert merged commit 0702f02 into open-policy-agent:main Feb 5, 2025
28 checks passed
@anderseknert anderseknert deleted the ast-store-poc branch February 5, 2025 18:38
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.

2 participants