framework/util: optimize get_rpm_nvr_by_type by adding a cache
The cache build could be optimized by assuming that all modules with
priority 100 are part of selinux-policy-<policytype> package. This way
the cache would only have to contain types from modules of other
priorities.
Another optimization would be making the cache persistent. This way it
would only have to be rebuild on policy reload (sedispatch could trigger
cache rebuild over dbus).
My testing shows significant time save when processing multiple AVCs:
setroubleshoot-server-3.3.24-1.el8:
real 2m26.075s
user 2m17.989s
sys 0m5.916s
Cache:
real 0m15.337s
user 0m11.004s
sys 0m3.995s
But curiously, there is also a small time save for individual AVCs
(measured by forcing the cache rebuild for each call of
get_rpm_nvr_by_type):
real 1m40.393s
user 1m32.830s
sys 0m5.960s
It could be caused by processing policy modules by lines, which quickly
eliminates all lines not starting by "(type " (as opposed to comparing
the regular expression with the whole file).