-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <anders@styra.com>
- Loading branch information
1 parent
da69c32
commit a7a48de
Showing
7 changed files
with
167 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package errors | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/open-policy-agent/opa/v1/storage" | ||
) | ||
|
||
// 160.8 ns/op 96 B/op 5 allocs/op // using fmt.Sprintf | ||
// 58.31 ns/op 8 B/op 1 allocs/op // using string concatenation | ||
// ... | ||
func BenchmarkNewNotFoundErrorWithHint(b *testing.B) { | ||
path := storage.Path([]string{"a", "b", "c"}) | ||
hint := "something something" | ||
|
||
for range b.N { | ||
err := NewNotFoundErrorWithHint(path, hint) | ||
if err == nil { | ||
b.Fatal("expected error") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters