I'm trying to speed up a slow operation triggered by a selection event
in a TraitsUI TreeEditor. I can profile the on_select event handler and
it tells me that the event triggers "122053 function calls (113250
primitive calls) in 0.675 seconds" which I find a surprisingly large
number. The on_select event handler dynamically swaps in a GUI panel
containing a bunch of TraitsUI widgets that are associated with the
selected TreeEditor node.
''' SpRegion represents a Region node in the TreeEditor '''
selection = Instance('SelectorPanel')
''' Tree selection event handler for region nodes '''
# Next line triggers lots of events
main_app.selector_panel = self.selection
Most of the time seems to be associated with doing this. According to
some profiler output, most of the time is spent handling traits events
(here http://pastebin.com/aGAAydaW with the application code here
http://github.com/AustralianSynchrotron/sinspect). Are there some better
tools than just profiling the event handler that might let me see
whether there is some race condition triggering a cascade of unnecessary
Trait events, and perhaps what the internally triggered events actually
are? How much activity should I expect as a result of swapping a
different panel instance? Any other tips for investigating this?