authz: cache prometheus metric lookup in subrepo
Created by: keegancsmith
Viewing the profile the most expensive function is getCompiledRules
. Surprisingly given the cache fast path, the slowest part of this function is in fact finding the prometheus metric given a list of labels. This minor change speeds up paths/s by 30%.
name old time/op new time/op delta
FilterActorPaths-32 3.75ms ± 7% 2.83ms ± 2% -24.54% (p=0.000 n=10+9)
name old paths/s new paths/s delta
FilterActorPaths-32 1.33M ± 7% 1.77M ± 3% +32.37% (p=0.000 n=10+9)
A deeper change is needed here where we cache most of the work here once per request, rather than doing it per file path. This requires a bit of refactoring, so just taking the quick wins from the benchmark first :)
Test Plan: go test