Skip to content

Commit 299b3ef

Browse files
committed
perf: AST compiler optimizations
Funnily, this started out as an attempt to look into issues reported with compiling large policy sets... before I realized that it isn't likely *this* compiler that has perf issues, but the one that "compiles" bundles as part of activation. So while these fixes likely does little to address that, there are still some rather nice improvements here, where the big ones as ususal are mostly just wins from avoiding work where it's possible. For benchmarking I've used Regal's embedded bundle, which isn't great to use over time, as it's a moving target. But since it's a pretty extensive bundle and one that covers most features of OPA, it's at least good for 1:1 comparisons when testing perf improvements. ``` // 66555594 ns/op 50239492 B/op 1083664 allocs/op - main // 62569440 ns/op 38723015 B/op 944277 allocs/op - compiler-optimizations pr ``` The B/op / alloc_space improvement is particularly nice here. What's noteworthy is how relatively little impact that has on performance in this case. That may be surprising but aligns pretty well with my previous experience of Go code where a lot of time is spend in recursive walks — that simply takes time, no matter how much you optimize. Oh well, less memory allocated for this is more memory to spend elsewhere. (I'm adding the benchmark used below to Regal in a parallel PR) Signed-off-by: Anders Eknert <anders@styra.com>
1 parent c872dce commit 299b3ef

16 files changed

Lines changed: 510 additions & 230 deletions

File tree

cmd/eval.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ func validateEvalParams(p *evalCommandParams, cmdArgs []string) error {
138138

139139
// check if illegal arguments is passed with unknowns flag
140140
for _, unknwn := range p.unknowns {
141+
if unknwn == "input" {
142+
continue
143+
}
141144
term, err := ast.ParseTerm(unknwn)
142145
if err != nil {
143146
return err

v1/ast/capabilities_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,16 @@ func TestCapabilitiesMinimumCompatibleVersion(t *testing.T) {
291291
}
292292
}
293293

294+
func BenchmarkCapabilitiesCurrentVersion(b *testing.B) {
295+
var caps *Capabilities
296+
for range b.N {
297+
caps = CapabilitiesForThisVersion()
298+
}
299+
if caps == nil {
300+
b.Fatal("expected capabilities to be non-nil")
301+
}
302+
}
303+
294304
func findBuiltinIndex(c *Capabilities, name string) int {
295305
for i, bi := range c.Builtins {
296306
if bi.Name == name {

0 commit comments

Comments
 (0)