Live data from Hacker News

Moving the mouse cursor can cause CPU spikes on macOS

mmazzarolo.com

1–10 of 28 posts

Re: Moving the mouse cursor can cause CPU spikes on macOS

#2
> I’d love to learn why and how Big Sur introduced this issue in macOS

It's just another manifestation of mobile is important and desktop can go hang.

You need to spin up when a human puts their finger on the touchscreen so you can have all the nifty animations and indications.

When the "cursor" isn't moving, you want to go to sleep to save battery.

Nobody cares that this isn't relevant when you have a mouse and monitor on a plugged in desktop.

Re: Moving the mouse cursor can cause CPU spikes on macOS

#5
I've been writing some UI widgets, and I bet this is caused by redrawing the widgets every time the mouse moves. I've not used Big Sur so I don't know if this is the case, but if they added highlights on mouseover, the easy way to make that work is redraw on every mouse move, just in case the mouse entered or exited a control. The slightly harder way, of course, is to detect transitions and only redraw then.

Re: Moving the mouse cursor can cause CPU spikes on macOS

#6
post #3

Hm, minimum OS scheduler timestep is usually around 1000hz, right? How do gaming mice go above that? I’ve seen up to 8000hz..

Events just get put into a queue, and somewhere in the guts of the application there will be a loop that does:

  while (stillRunning) {
    event = getEventOrWait();
    // handle event
  }
(In macOS this is done inside [NSApp run], but Windows and Linux make the loop explicit.)

I think the 1000 Hz you are thinking of is the accuracy of the UI timers. Since you're just calling this in a loop, not waiting for a timer to fire, you can burn through a lot of events in one timeslice. And since most systems have multiple processors, it is reasonable for your game to be running continually, especially since modern OSes frequently prioritize certain kinds of programs (and a game might request prioritization if at all possible).

Re: Moving the mouse cursor can cause CPU spikes on macOS

#8
I’m surprised people are only noticing this on Big Sur, since I’ve been seeing this as early as Mojave using a 1kHz ‘gaming’ mouse. (It may have happened in even earlier versions of the OS and is just getting progressively worse on every new macOS release…)

I suspect this is at least part of the reason why some people have mysterious performance problems with VirtualBox on macOS[0]—at least, it’s how I first noticed the problem. (I’m sure VirtualBox has some other issue going on too, since its event queue gets backed up so badly that even keyboard events become delayed. Life gets interesting when the delays are so long that the guest OS key repeat is triggered!)

Does anyone know of some small utility that adjusts mouse polling rates to at least mitigate the issue? The official Logitech software to do this is 476MB, 5 kernel extensions, and a launch daemon, which is a bit much just to send a USB command.

[0] https://www.virtualbox.org/ticket/16436

Re: Moving the mouse cursor can cause CPU spikes on macOS

#9

I recently learned that moving my mouse was causing the coil whine sound coming from my Win10 gaming PC. Turning down the polling rate on my mouse was the only fix that worked.

I started getting coil whine yesterday, after adjusting my fan curves. Not really sure why, but with the fans off the whine was far louder than keeping them on a low-speed minimum. It’s not fan noise blocking out the coil whine, because I still can’t hear the fans (they’re Noctua’s). I don’t know if it’s due to thermals, something to do with the power load, or what.

I’ll have to look at the polling rate thing, too - thanks for the tip.

Re: Moving the mouse cursor can cause CPU spikes on macOS

#10
post #9

I recently learned that moving my mouse was causing the coil whine sound coming from my Win10 gaming PC. Turning down the polling rate on my mouse was the only fix that worked.

I started getting coil whine yesterday, after adjusting my fan curves. Not really sure why, but with the fans off the whine was far louder than keeping them on a low-speed minimum. It’s not fan noise blocking out the coil whine, because I still can’t hear the fans (they’re Noctua’s). I don’t know if it’s due to thermals, something to do with the power load, or what. I’ll have to look at the polling rate thing, too -…

I wonder if the vibrations from the fans cause the coils to change shape slightly, preventing them from supporting the higher frequency of coil whine?
Post reply on HN