opa
opa copied to clipboard
[Perf] Cache schema types
What is the underlying problem you're trying to solve?
Type checking is very time-consuming with a large number of rules. I noticed that the schema is compiled for each rule , but the result is not cached.
Describe the ideal solution
typeChecker can cache schema types.
Additional Context
We use about 500 Rego files and a large JSON schema. If you don't mind, I can open a PR with a solution to this issue.
I did a comparison of the current version of OPA and with caching:
Before
11.30 real 19.01 user 0.24 sys
220233728 maximum resident set size
0 average shared memory size
0 average unshared data size
0 average unshared stack size
12513 page reclaims
1147 page faults
0 swaps
0 block input operations
0 block output operations
0 messages sent
0 messages received
3164 signals received
1425 voluntary context switches
34594 involuntary context switches
196114350840 instructions retired
54559370628 cycles elapsed
158878016 peak memory footprint
After
0.69 real 0.98 user 0.08 sys
207503360 maximum resident set size
0 average shared memory size
0 average unshared data size
0 average unshared stack size
11718 page reclaims
1163 page faults
0 swaps
0 block input operations
0 block output operations
0 messages sent
0 messages received
217 signals received
92 voluntary context switches
2432 involuntary context switches
10168081937 instructions retired
3013213385 cycles elapsed
146622784 peak memory footprint
Interesting! I haven't experienced this myself in Regal, where we pass the input schema when running tests. But that could be that it's simply a smaller schema, us using the same schema for everything using the subpackages scope... or simply that we only have ~200 .rego files compared to your 500.
If you don't mind, I can open a PR with a solution to this issue.
Of course! Thanks 😃
The size of our scheme is about 200kb in compressed form.
Ooof, ours is 8kb uncompressed, so yes, that'll explain it.