So upon investigating a new plugin that has to traverse a *lot* of registry
keys. In so doing, it calls is_valid_address often which calls
HiveAddressSpace vtop, which calls the following:
self.hive.Storage[ci_type].Map.Directory[ci_table].Table[ci_block].BlockAddress
Every time these ctypes try an attribute lookup, they pass through two
exception handlers that are both expected to fail. Unfortunately when an
exception is caught, it's a bit costly (very minor hit if it doesn't get
caught):
$ python -m 'timeit' -s 'd=dict(zip(range(1000), range(1000)))' $'try:
d[1999]\nexcept KeyError: pass'
1000000 loops, best of 3: 2.73 usec per loop
$ python -m 'timeit' -s 'd=dict(zip(range(1000), range(1000)))' $'1999 in d and
d[1999]'
10000000 loops, best of 3: 0.151 usec per loop
As such we should be trying to avoid doing try/catches that we expect to catch
an exception. I've attached an initial patch that uses __getattr__ instead of
__getattribute__ (and therefore will only get called after that standard
attribute check has failed). Unfortunately I can't figure out what some of the
code's for (checking "_" + attr?) and whether there will be unusual side
effects, so a review and/or discussion about the changes would be much
appreciated... 5:)
Original issue reported on code.google.com by mike.auty@gmail.com on 27 Apr 2011 at 6:02
Original issue reported on code.google.com by
mike.auty@gmail.com
on 27 Apr 2011 at 6:02Attachments: