[dabo-dev] Profiling dEvents.py

Author: Paul McNett

Posted: 2004-12-16 at 21:50:03

In dabo/dEvents.py, in Event.__init__(), comment out these two lines:

#self._insertEventData()

#self._logEvent()

And notice how much faster Dabo runs. Specifically, go to a

dDataNavPage, requery, and use the arrow key up/down in a grid of a

bunch of items. Go to the edit page and scroll around. Try it with those

lines commented and without.

These are two of our bottlenecks. The other major one is in object

instantiation, specifically the propertyHelperMixin.getPropertyList()

that runs an eval on every single item in dir(self) to find the ones

that are properties (and there are dozens if not hundreds of items in

the dir()). That one is only run in instantiation though so it is really

NBD.

New event objects are constantly being created though, so everything we

do in there just adds to the cumulative time. I think we can turn on/off

the call to _logEvent() based on a global setting: you only care about

event logging at design time, if even then. As far as _insertEventData()

there are specific things we need from the wx event but maybe as we go

forward we can widdle that list down or come up with a better way.

Perhaps the dEvents would actually be a good candidate for moving to a

C++ lib. Or maybe the problems I had before using the wx Events directly

will be resolved in future wx versions.

I tracked these things down using the builtin profile and pstats modules

- have you tried those yet? Here is how I did it - in my main.py for a

Dabo app:

if __name__ == "__main__":

import sys

if len(sys.argv) > 1:

if sys.argv[1].lower() == "profile":

import profile

profile.run('main()', 'profile')

import pstats

p = pstats.Stats('profile')

p.strip_dirs()

print "\n========= Ten functions with highest cumulative time ========="

p.sort_stats('cumulative').print_stats(10)

print "\n\n========= Ten functions with highest time in the function

========="

p.sort_stats('time').print_stats(10)

sys.exit()

main()

... so instead of 'python main.py' I can type 'python main.py profile'.

Just FYI, this may be old news to you. I had noticed Dabo getting slower

over the past few months so it is good to know where the bottlenecks are

- I had already suspected the dEvents but the getPropertyList()

bottleneck surprised me at first.

--

Paul McNett

http://paulmcnett.com

©2004 Paul McNett