mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
739777cfff
This pretty substantially improves performance by avoiding to do a JSON round trip and then converting into AST types. There are a couple of fields left that require the round trip, we can iterate on this as needed to supply better options for the results and metrics. This custom ASTer leaves out the rule counts, which also helps to improve the performance. On my local machine the numbers look like: ``` name old time/op new time/op delta MaskingNop-8 129µs ± 1% 110µs ± 1% -15.19% (p=0.000 n=7+10) MaskingRuleCountsNop/1Rules-8 138µs ± 1% 111µs ± 1% -19.34% (p=0.000 n=10+10) MaskingRuleCountsNop/10Rules-8 180µs ± 1% 116µs ± 4% -35.70% (p=0.000 n=10+10) MaskingRuleCountsNop/100Rules-8 614µs ± 1% 113µs ± 1% -81.66% (p=0.000 n=10+8) MaskingRuleCountsNop/1000Rules-8 5.16ms ± 2% 0.11ms ± 1% -97.79% (p=0.000 n=10+10) MaskingErase-8 148µs ± 2% 129µs ± 0% -12.65% (p=0.000 n=10+10) name old alloc/op new alloc/op delta MaskingNop-8 56.7kB ± 0% 48.0kB ± 0% -15.43% (p=0.000 n=10+10) MaskingRuleCountsNop/1Rules-8 59.5kB ± 0% 48.0kB ± 0% -19.41% (p=0.000 n=10+10) MaskingRuleCountsNop/10Rules-8 84.9kB ± 0% 48.0kB ± 0% -43.47% (p=0.000 n=10+10) MaskingRuleCountsNop/100Rules-8 362kB ± 0% 48kB ± 0% -86.73% (p=0.000 n=9+10) MaskingRuleCountsNop/1000Rules-8 3.26MB ± 1% 0.05MB ± 0% -98.52% (p=0.000 n=10+10) MaskingErase-8 65.7kB ± 0% 57.0kB ± 0% -13.33% (p=0.000 n=10+10) name old allocs/op new allocs/op delta MaskingNop-8 1.23k ± 0% 1.12k ± 0% -8.46% (p=0.000 n=10+10) MaskingRuleCountsNop/1Rules-8 1.31k ± 0% 1.12k ± 0% -14.32% (p=0.000 n=10+10) MaskingRuleCountsNop/10Rules-8 1.98k ± 0% 1.12k ± 0% -43.30% (p=0.000 n=10+10) MaskingRuleCountsNop/100Rules-8 8.74k ± 0% 1.12k ± 0% -87.13% (p=0.000 n=10+10) MaskingRuleCountsNop/1000Rules-8 76.3k ± 0% 1.1k ± 0% -98.52% (p=0.000 n=10+10) MaskingErase-8 1.33k ± 0% 1.22k ± 0% -7.84% (p=0.000 n=10+10) ``` So the performance no longer scales with the number of rules hit, and overall the base cost is almost 20% faster. This time directly impacts round trip latency for OPA REST clients performing evaluations. Signed-off-by: Patrick East <east.patrick@gmail.com>