Opened 10 years ago

#28 new defect

Under GTK, plot panel consumes high CPU even when idle

Reported by: flip Owned by: bsoher
Priority: major Milestone:
Component: common Version:
Keywords: Cc: flip

Description

Under Ubuntu & Fedora (both using wxPython 2.8.11.0 but also seen in earlier
versions of wx), whenever a plot panel is visible (e.g. Simulation visualize
tab, rfpulse tranformations), I see high CPU use (>75%) as reported by top. Some
debugging shows that the plot panel is being sent approx 12-15 EVT_SIZE events
every second, each followed by an EVT_IDLE during which the plot panel actually
responds to the size change.

I don't see this under OS X or Windows.

The culprit seems to be this line in PlotPanel._set_size():

self.canvas.SetSize( pixels )

When I comment that out, the problem goes away. I don't know enough about
matplotlib to speculate what's going on there.

To debug, I added this to PlotPanel._on_size():

import time
size = event.GetSize()
print "_on_size @ %f, size = (%d, %d)" % (time.time(), size.x, size.y)


Sometimes the size wobbles by one pixel, e.g. from (200, 353) to (200, 352) and
back again. In this case it's no wonder that this eats up the CPU -- a size
event is sent and the plot panel responds by changing its size by one pixel
which generates another size event. But at other times I see the same size
reported over and over and I can't figure out why setting the panel to its
current size would generate another size event.

I'm able to short-circuit this problem by adding this to PlotPanel._set_size():

self._last_size = pixels


Then in _on_size() I ignore the size event if the new size suggested by the
event only differs from self._last_size by <= 1 pixel. This stops the flood of
size events without having any negative effect (that I can see) on behavior.

IMO my fix is a hack because it fixes the symptom (high CPU use) without curing
the disease (spurious size events). A proper solution would not have to resort
to ignore events. I'll commit my fix but leave this ticket open to track the
fact that this problem isn't really fixed.

Change History (0)

Note: See TracTickets for help on using tickets.