Serious CPU issue with PopupMenu


#1

Hi Jules,

There is a big CPU hit using PopuMenu in the SVN version

Try this:

Open Windows Task Manager,
Run Juce Demo using the current tip
Open the look and feel menu for example, the CPU will jump to either 50% or 100% depending if you have a dual processor or a mono.

Do the same thing using the precompiled juce demo from the website,
the CPU stay low.

It doesn’t seem to be a problem on OSX though.

Any idea ?

Thanks,


#2

maybe in MessageManager::runDispatchLoopUntil
we should add Thread::sleep(millisecondsToRunFor)
if juce_dispatchNextMessageOnSystemQueue returns false ?


#3

I’d never noticed that before, but yes, it looks like you’re right, it does seem to be spinning there.

I think it’d have to be quite a short sleep so that it stays responsive to new messages, but something like 5ms would probably be ok:

if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0)) Thread::sleep (5);


#4

isn’t the millisecondsToRunFor supposed to be this value ?
It’s 20 ms if I remember correctly.

Or maybe

bool res = juce_dispatchNextMessageOnSystemQueue(millisecondsToRunFor>= 0); if (!res) { int64 sleepTime = endTime - Time::currentTimeMillis(); if (sleepTime > 0) Thread::sleep(sleepTime); }


#5

Well, not really - the millisecsToWaitFor is how long the whole method is allowed to take - there’d be no point locking it up for the whole duration, when other methods might be arriving.

But you’re right that the end time should be taken into account - I think I’ll go for this:

            if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
            {
                const int msToWait = (int) (endTime - Time::currentTimeMillis());

                if (msToWait > 0)
                    Thread::sleep (jmin (5, msToWait));
            }

#6

Sounds good to me.
As it didn’t happen in older version of Juce, do you remember what might have caused this code modification ?


#7

[quote=“otristan”]Sounds good to me.
As it didn’t happen in older version of Juce, do you remember what might have caused this code modification ?[/quote]

I redesigned the way modal loops work as part of the cocoa updates.


#8

oki doki.

Thanks,