mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-14 12:22:51 -06:00
3810973ab1
It's been irritating me for long how `opa bench` has such a high baseline metric for even the most trivial queries, as in order to know the cost of "your" Rego you'll need to first subtract the number OPA adds for just getting eval set up. This improves this somewhat by not initiating some caches until they're needed. We don't need to cache comprehensions to eval the value '1', or a functionMockStack, and so on. In fact, we may never need one. The gain here is miniscule for real policy evaluation, but helps some with making `opa bench` approach a more reasonable baseline. We *can* have 10 allocs more removed if we initialize and reuse a base cache and a virtual cache across all runs. This works as the query is the same for all runs. However, since those are normally initialized per "run" (query), perhaps that's going too far? ``` opa bench 1 ``` **Before** ``` +-------------------------------------------+------------+ | samples | 398083 | | ns/op | 2978 | | B/op | 3200 | | allocs/op | 49 | +-------------------------------------------+------------+ ``` **After** ``` +-------------------------------------------+------------+ | samples | 432841 | | ns/op | 2825 | | B/op | 2968 | | allocs/op | 40 | +-------------------------------------------+------------+ ``` This change also fixes a panic which happened when the `--metrics` flag was set to `false`. Signed-off-by: Anders Eknert <anders@styra.com>