Commit graph

1 commit

Author SHA1 Message Date
Inseob Kim
55d140f904 Use heuristics to run sepolicy_tests faster
We are compiling regex more than 300000 times, and it's a main
bottleneck for slow sepolicy_tests. Actually we don't need to compile
regex that much; most of cases can be handled by simple string
comparison. This change introduces heuristics for optimization.

Bug: 301874100
Test: verified that return values of MatchPathPrefix are not changed.
Test: run cProfile, before and after.

Before
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    21951    0.923    0.000   56.491    0.003 policy.py:33(MatchPathPrefix)

After
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    21951    0.078    0.000    1.159    0.000 policy.py:40(MatchPathPrefix)

Change-Id: I1ebad586c2518e74a8ca67024df5e77d068e3ca5
2023-09-26 16:47:45 +09:00