User forums > Help

CPU 100% when moving mouse in CB (toolbar/editor/manager/etc)

<< < (2/3) > >>

thomas:
The main problem lies in two things. First, during the UpdateUI handler, menu items and other controls are enabled/disabled and this fires off new UpdateUI messages. Second, wxWidgets sends messages to many objects that aren't updated at all, but just happen to be a child of the same window... for example the editor is notified if you move the mouse over the menu bar or over the project manager.

I'm not sure whether it would work to only listen to the events using one single handler. In any case that would mean to rely on a misfeature (which may be implemented differently on another platform or in another version).

Setting a flag to not process the events won't do much. Our message processing is not what eats up the CPU time, it is pushing a several thousand events through the message queue. wxWidgets will still send them, even if we ignore them.
Using a timer and poll events every 100 ms or so would be great, but unluckily I don't see a way how you can do that with wxWidgets. For all I know there are no functions to actually manipulate the event queue in such a way as we would need (peek at and pop off one message, then remove all duplicates).

A solution that would work would be to move the control updating code to a manager that keeps track of and handles the states of all controls, but that would require an awful lot of work in the present design. Knowing that this design will be replaced one not-so-far day in the future, I'm reluctant to do that work, too.

Biplab:

--- Quote from: thomas on March 08, 2007, 11:13:02 am ---Using a timer and poll events every 100 ms or so would be great, but unluckily I don't see a way how you can do that with wxWidgets. For all I know there are no functions to actually manipulate the event queue in such a way as we would need (peek at and pop off one message, then remove all duplicates).

--- End quote ---

AFAIK, No timer is necessary. You need to set UpdateInterval during app initialization. The following code should do the job.

--- Code: ---wxUpdateUIEvent::SetUpdateInterval(100);
--- End code ---

It will set the value of updating ui to 100 milliseconds. :)

I tested it sometimes back for one of my app.

Regards,

Biplab

thomas:
I don't see why this should reduce the CPU load, as it does not reduce the actual number of events being sent, but... I tried it, and it really works :)

On my machine, this one line of code reduces the load from 26-29% to 3-4%.

Good catch, Biplab  8)

Biplab:
Thanks a lot for testing it. :D


--- Quote from: thomas on March 08, 2007, 07:09:38 pm ---On my machine, this one line of code reduces the load from 26-29% to 3-4%.

--- End quote ---

So are we going to put this to main repo? ;)

Regards,

Biplab

thomas:
Did that before posting already.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version