Files
releases/cmd
Anders Eknert 3810973ab1 perf: improve "baseline" metrics of opa bench for trivial queries (#7580)
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>
2025-05-15 15:34:44 +02:00
..
2025-01-31 20:24:05 +01:00
2025-01-31 20:24:05 +01:00
2024-12-12 15:27:34 +01:00
2024-12-12 15:09:03 +01:00
2024-12-12 15:09:03 +01:00
2025-01-30 09:57:27 +01:00
2025-05-12 13:57:48 +02:00
2025-01-31 20:24:05 +01:00
2025-02-01 10:37:53 +01:00
2024-12-12 15:27:34 +01:00
2024-12-12 15:27:34 +01:00