Opened 12 years ago

Closed 12 years ago

#11315 closed defect (fixed)

wxTimer usage leads to excessive CPU usage when app is idle

Reported by: mschwendt Owned by: pcor
Priority: normal Milestone:
Component: wxGTK Version: 2.8.10
Keywords: Cc: businessmanprogrammersteve@…, dan@…
Blocked By: Blocking:
Patch: no

Description

There have been bug reports about Audacity, which uses wxWidgets/GTK2, pointing out that if the application is left idle for some time, CPU usage will increase slowly but steadily.

One thread discusses it here:
http://sourceforge.net/mailarchive/message.php?msg_name=20091011120400.2fad6a52%40faldor.intranet

[...]

I've found out that AMule is affected, too. What AMule and Audacity have in common is that they use wxTimer.

[...]

wxTimer timeout callback runs wxApp::WakeUpIdle() which in turn runs wxapp_install_idle_handler() which causes more and more wxAddEmissionHook()'s to pile up. Due to that, wxGTK spends an increasing time in glib2's g_signal_add_emission_hook(). Only when touching the application or giving it focus, event_emission_hook() gets called and removes hooks by returning False.

Change History (6)

comment:1 Changed 12 years ago by mschwendt

  • Summary changed from wxTimer usage leaders to excessive CPU usage when app is idle to wxTimer usage leads to excessive CPU usage when app is idle

comment:2 Changed 12 years ago by aldimond

  • Cc businessmanprogrammersteve@… added

Just to be specific about this, an increasing amount of time (up to 100% CPU if left idle for long enough) is spent in g_hook_insert_before(), appending a GHook node to a linked list. This list grows quite large (240,000 nodes in 15 minutes of idling on my system, for example), and the increasing length of the list is the reason that CPU usage gradually increases.

comment:3 Changed 12 years ago by sharkcz

  • Cc dan@… added

comment:4 Changed 12 years ago by robind

  • Status changed from new to confirmed

This has also been reported by wxPython users with wxStyledTextCtrl in their apps. wxStyledTextCtrl has a timer that is used for things like flashing the caret.

comment:5 Changed 12 years ago by pcor

  • Owner set to pcor
  • Status changed from confirmed to accepted

comment:6 Changed 12 years ago by PC

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [62397]) Avoid installing emission hook more than once.
It was possible for an app using a timer, but triggering no events, to
accumulate an unbounded number of hooks, consuming large amounts of CPU time
in processing the hook list.
Fixes #11315.

Note: See TracTickets for help on using tickets.