Files
Anders Eknert cc4783a0cc perf: opa fmt 3x faster formatting (#7341)
We have a Regal rule checking that a file is formatted, making the
performance of the formatter more important than it normally might be.

Since I did some work on this in Regal recently, I was curious to see
if this could be improved. Turned out to be a few bottlenecks that we
could remove with great results. The Regal policies are possibly not
representative for all kinds of Rego, and one thing that stands out is
thay they have a *lot* of metadata annotations. Turned out that comment
processing was the main bottleneck, so improving this meant a huge
boost for formatting a typical Regal policy. The improvements here
should make formatting of any file faster though.

**BenchmarkFormatLargePolicy-10 main**
```
382	   3064960 ns/op	 4573131 B/op	   26266 allocs/op
```

**BenchmarkFormatLargePolicy-10 opa-fmt-perf**
```
1396	    812859 ns/op	  362651 B/op	    8811 allocs/op
```

Signed-off-by: Anders Eknert <anders@styra.com>
2025-02-06 10:37:52 +01:00
..