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

Even less allocs #7190

Merged
merged 1 commit into from
Nov 24, 2024
Merged

Conversation

anderseknert
Copy link
Member

main

BenchmarkLintAllEnabled-10    1	2640715625 ns/op	6385110200 B/op	116296633 allocs/op

pr

BenchmarkLintAllEnabled-10    1	2597179708 ns/op	6183614112 B/op	108421141 allocs/op

(I renamed the benchmark, but this is the same as "regal linting itself" used in the past)

Another 8 million allocations cut off from regal lint bundle, and a whopping 10% improvements to wall clock time!

The most significant improvement is the Equal implementation for refs, since that is called all over the place. But there are many other fixes here, and they all contribute something substantial (and fixes that only have had marginal impact have been left out).

**main**
```
BenchmarkLintAllEnabled-10    1	2640715625 ns/op	6385110200 B/op	116296633 allocs/op
```

**pr**
```
BenchmarkLintAllEnabled-10    1	2597179708 ns/op	6183614112 B/op	108421141 allocs/op
```

(I renamed the benchmark, but this is the same as "regal linting itself"
used in the past)

Another 8 million allocations cut off from `regal lint bundle`,
and a whopping 10% improvements to wall clock time!

The most significant improvement is the Equal implementation for
refs, since that is called all over the place. But there are many
other fixes here, and they all contribute something substantial
(and fixes that only have had marginal impact have been left out).

Signed-off-by: Anders Eknert <anders@styra.com>
Copy link

netlify bot commented Nov 24, 2024

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 3ada4d3
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/6742f0b91d0f090008c62a5c
😎 Deploy Preview https://deploy-preview-7190--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -403,7 +406,8 @@ func (e *eval) evalStep(iter evalIterator) error {
})
}
case *ast.Term:
rterm := e.generateVar(fmt.Sprintf("term_%d_%d", e.queryID, e.index))
// generateVar inlined here to avoid extra allocations in hot path
rterm := ast.VarTerm(fmt.Sprintf("%s_term_%d_%d", e.genvarprefix, e.queryID, e.index))
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that the compiler couldn't inline that itself 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if it was possible for the compiler to inline, but it’s a little more elaborate, as our manual inlining also reduces 2 sprintf calls to one

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

LGTM. Just curious about the compiler not being able to inline generateVar itself; it looks simple enough...

@anderseknert anderseknert merged commit a60ef72 into open-policy-agent:main Nov 24, 2024
28 checks passed
@anderseknert anderseknert deleted the even-less-allocs branch November 24, 2024 10:24
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