[apparmor] [patch] - performance again... small changes

Christian Boltz apparmor at cboltz.de
Thu Nov 27 18:16:50 UTC 2014


Hello,

Am Donnerstag, 27. November 2014 schrieb Peter Maloney:
> On 11/27/2014 12:36 AM, Seth Arnold wrote:
> > On Wed, Nov 26, 2014 at 10:57:13PM +0100, Peter Maloney wrote:diff
> > -ur apparmor.orig/aamode.py apparmor.p1/aamode.py ---
> > apparmor.orig/aamode.py	2014-07-14 20:56:26.000000000 +0200 +++
> > apparmor.p1/aamode.py	2014-11-09 22:15:01.875415033 +0100
> > 
> > ...
> > 
> > -MODE_MAP_RE = re.compile('(r|w|l|m|k|a|x|i|u|p|c|n|I|U|P|C|N)')
> > +MODE_MAP_LIST = ["r", "w", "l", "m", "k", "a", "x", "i", "u", "p",
> > "c", "n", "I", "U", "P", "C", "N"]
> > 
> > ...
> > 
> > +    for mode_char in string:
> > 
> > +        if mode_char not in MODE_MAP_LIST:
> >              break
> > 
> > ...
> > The mode.split("::") speedup makes a ton of sense. I'm less
> > convinced of the MOD_MAP_LIST lookup, that's a long list to iterate
> > through. If you're up for more testing, I'm curious about the
> > performance difference of only the :: splitting, only the
> > MODE_MAP_LIST, and perhaps using MOD_MAP_SET = { 'r', 'w'. 'l',
> > ...} as well.
> > 
> > For just the split_log_mode() change,
> > Acked-by: Seth Arnold <seth.arnold at canonical.com>
> 
> Yes I agree that a dict would likely be faster than a list, even a
> small list like that one. (attached new patch)
 
> >>> timeit(testlist, number=10000)
> 
> 0.0441557650001414
> 
> >>> timeit(testset, number=10000)
> 
> 0.016543965999971988

Interesting difference when measured in percent, less interesting when
counting seconds ;-)

That said -
Acked-by: Christian Boltz <apparmor at cboltz.de>
and commited to bzr.


BTW: MODE_MAP_LIST and MODE_HASH.keys() aren't too different:

['A', 'C', 'I', 'K', 'L', 'M', 'N', 'P', 'R', 'U', 'W', 'X', 'a', 'c', 'i', 'k', 'l', 'm', 'n', 'p', 'r', 'u', 'w', 'x']   <= sorted(MODE_HASH.keys()
[     'C', 'I', 'N',                'P',      'U',           'a', 'c', 'i', 'k', 'l', 'm', 'n', 'p', 'r', 'u', 'w', 'x']   <= sorted(MODE_MAP_SET)

This brings us to the questions
a) if it makes sense to allow uppercase A L M R W X
b) if MODE_MAP_LIST should also contain N


Regards,

Christian Boltz
-- 
Sorry, mit java kenne ich mich gar nicht aus, das ist mir einfach zu
unportabel.                           [Thorsten Kukuk in suse-linux]




More information about the AppArmor mailing list