Sure, I can get spurious WM_MOUSEMOVE messages, but why do they keep streaming in?


I wrote some time ago that the window manager generates spurious WM_MOUSEMOVE messages in order to let programs know that the mouse has entered the window even if the reason was a window hierarchy reshuffle rather than a physical motion of the pointing device. But some people have noticed that that explanation fails to account for all the WM_MOUSEMOVE messages that are being delivered. In particular, the reasoning fails to explain why a stream of WM_MOUSEMOVE messages is being generated. So where is this infinite stream of WM_MOUSEMOVE messages coming from, even when the window hierarchy is stable?

They're most likely coming from some third party so-called enhancement software.

The Windows performance and mobility teams keep a close eye on these sort of continuous phenomena. The performance folks are interested because this continuous stream of messages suck away resources that could be used for something more productive. It's not just the cost in CPU. The memory in the message handling code path can't be paged out since it's being hit all the time. The context switches force CPU caches to be flushed. Algorithms which had been tuned to reside entirely within the L2 cache now find themselves going out to slower main memory. Meanwhile, the mobility team is concerned because all this continuous activity runs down your battery, prevents the CPU from going into a low-power state, and prevents your screen saver from kicking in.

If you find a continuous stream of WM_MOUSEMOVE messages, then there is some continuous activity going on that is causing it. It might be some software that is polling the mouse in order to provide "extra value". For example, they might check the mouse cursor position and try to guess what it is positioned over, but they never realize that "You know, if nothing has changed, the answer is probably the same as it as last time you checked." Or, as the author of linked posting above eventually figured out, it might be a buggy wireless mouse which not only is sucking down your CPU and preventing your screen saver from running, but is also draining your wireless mouse battery!

Comments (20)
  1. someone else says:

    Interesting. So, how do we get search and destroy this enhancement software?

  2. John says:

    Nuke it from orbit; it’s the only way to be sure.

  3. IgorD says:

    My 2005 LG Notebook had a fax software that wrote like 20 times a second to the Registry some value that probably meant that we’re not receiving any fax right now. Mark Russinovich’s utility helped me find out why is disk light non-stop blinking.

  4. The solution: just remove all the crapware that comes with your brand new computer, and install just the programs you need. Or easier: if your support terms and software license allow for it, wipe away the hard drive and do a fresh Windows install from an unmodified Microsoft disk. This may not solve the problem with the faulty wireless mouse, but will do away with all those programs that make Windows Vista seem slower on a Code Duo than Windows XP was in a Pentium II.

  5. ton says:

    "Or, as the author of linked posting above eventually figured out, it might be a buggy wireless mouse which not only is sucking down your CPU and preventing your screen saver from running, but is also draining your wireless mouse battery!"

    I sincerely believe that one of the biggest problems that contributes to low quality software is vendors not using the miserable software that they themselves wrought. An even bigger issue is a general ignorance of best practices like basic unit testing, source control, code review, performance testing,etc. Shameful.

  6. ender says:

    My usual procedure when I set up a new computer for a client is to first reinstall Windows from a clean CD. Since I started doing this, the amount of trouble I have with various computers after they’ve been in use for a while has gone down significantly.

  7. On a related note, yesterday a colleague told me his laptop had started locking up. I investigated, and it turned out Explorer was no longer responding to (or receiving?) mouse messages – but keys still worked. Other applications seemed to be behaving a little oddly, sometimes ignoring clicks, sometimes treating left clicks as right clicks instead. Presumably something was trying to hook events and screwing it up horribly, but being a brand new big name laptop (i.e. preinstalled with a terabyte of random dross of little value and less quality) , I have far too many obvious suspects…

  8. Lisa says:

    Sometimes DirectX initialization can cause this, particularly changing the display mode or allocating certain types of new surfaces especially on older DX versions. I assume this is tied to the window manager thing, as DX binds the surface to a window (even if the window is not visible, it’s still there and has a handle).

    Granted, you shouldn’t be allocating surfaces continually so it shouldn’t be *sustained* mouse move messages but getting a long burst of them is fairly normal. I also don’t doubt that some apps aren’t smart enough to handle surfaces correctly either. :( A number of non-game of apps use DirectX and aren’t obvious about it, i.e. paint programs and some document readers.

  9. Alexandre Grigoriev says:

    “The memory in the message handling code path can’t be paged out since it’s being hit all the time.”

    Raymond,

    I think the time to worry about code not able to page out is long long over. This code path is naturally exercised every darn half second.

    [I think you’ll find that there are often many long stretches of time where a window receives no messages at all, thereby permitting the message handler to be paged out. -Raymond]
  10. Drak says:

    @James Sutherland:

    Ahhhh. Now I understand this guy that was at my local computer store returning his laptop because the pointer wouldn’t move. (He had a lot of trouble explaining it to the guy behind the counter, and I figured it would be SUE.)

    Could have been the same brand :)

  11. Reminds me of old times (Win 3.11) when we wrote a screensaver without the provided srnsave.lib. At one of the customers secretary the screensaver would always stop after a few frames.

    It was probably a dumb driver that continuously sent WM_MOUSEMOVE with the same coordinates over and over. We changed the screensaver code to only auto-shutoff if the mouse moved a significant amount instead of the first instance WM_MOUSEMOVE was received.

  12. Alexandre Grigoriev says:

    [I think you’ll find that there are often many long stretches of time where a window receives no messages at all, thereby permitting the message handler to be paged out. -Raymond]

    You didn’t get the point. You should not want your code to page out anymore. Vista, finally (like 5 years later than necessary), doesn’t call SetProcessWorkingSetSize(h, -1, -1) anymore in its default main window minimize handler. And Win2008 doesn’t page the kernel stacks, too!

    I wonder if the people who wanted the code to page out too much are responsible for horrible performance of file cache with large files in XP. Basically, if you copy large files, it broke MRU logic for the code sections and seemed cause code page-in thrashing.

  13. Jules says:

    Alexandre… tell me about it.  Mastering a DVD image on a machine with < about 1GB of RAM would always leave everything swapped out.  Really annoying.

    Linux does the same, but you can ‘echo 0 > /proc/sys/vm/swappiness’ (or some similar incantation).  Unfortunately, I don’t think there’s any similar control for the XP kernel’s willingness to swap out applications to grow the cache.

  14. Alexandre Grigoriev says:

    Jules,

    I wish authors of those video/DVD authoring applications read the SDK docs at least once in a year, and learnt about FILE_FLAG_NO_BUFFERING. Oh, and CopyFile(Ex)/SHFileOperation functions’ owners, too, must do that.

    [A common theme: “You idiots you should do thing X.” “Um, we already do thing X.” -Raymond]
  15. Josh says:

    @Alexandre: You do want your code to page out.  One, because writing it to disk does not require removing it from RAM; paging out pre-emptively means that if you suddenly need a lot of RAM, you can immediately free unused RAM, instead of writing to disk and then freeing (which can be particularly costly if you are also reading from the same disk).  Ever piece of code that refuses to page is less active RAM available to the process currently being used, so why not page it out if it hasn’t been used in a while?  Making the active program run 5% faster for minutes or hours is worth a quarter second pause when you eventually leave it.

    That said, the XP minimize paging (which didn’t seem to leave it in RAM) was a waste, but only because it got the definition of minimize wrong.  I suspect the initial designers thought "If they are switching away briefly, they’ll just switch focus, while minimizing is for programs they won’t use for a while."  In practice, people use minimize all the time, even for short switches, and the computer was overzealously freeing RAM for the new active program.  A good idea, poorly executed, due to inaccurate perceptions of user behavior.

  16. Alexandre Grigoriev says:

    Josh,

    You should not sweat about not being able to page out (discard) a code path which is exercised often during normal use, anyway.

    Working set trimming performed during minimization, misfires badly, because when you lock the user’s session, all apps are sent a minimize command. When you open it back, all will get a restore command. In this case, especially if it’s a home computer used by different family members, getting these apps back into memory takes like a minute or so of intensive paging-in.

    It made some sense in time of 32 MB RAM, but this time is long gone. Unfortunately, even XP SP3 still keeps doing that. I wish there was a registry setting to disable it.

  17. Alexandre Grigoriev says:

    [A common theme: “You idiots you should do thing X.” “Um, we already do thing X.” -Raymond]

    I thought that should have been done in 2002. Me, particularly, has been bitching about that since I started using DVD-R.

    [So you want a time machine? -Raymond]
  18. nksingh says:

    @Alexandre:

    "And Win2008 doesn’t page the kernel stacks, too!"

    I’m pretty sure it does page kernel stacks (why do you think we would fork our kernel behavior between server and client in an area so trivial?).

  19. Alexandre Grigoriev says:

    @nksingh,

    Of course, I don’t have an opportunity to see all the intricacies of actual Win2008 code, but from my observation of Win2008 kernel during my driver debugging, I never saw a kernel stack paged out. As opposed to Win2003, where some threads were always paged out. Even kernel worker threads (IoQueueWorkitem).

    And if you think of it more, this stack paging is now a misfeature which should have been killed in Win2003 timeframe. Again, it’s not 32MB epoch anymore. If you have 2000 threads all in UserMode wait state, you would only save 8 MB or so of non-pageable memory. Is it worth the trouble at all? Just don’t tell me that 8 MB is the straw that breaks the camel’s back.

    [In which case I don’t want to hear you complaining about how newer versions of Windows use more memory than older versions of Windows – they’re just following your recommendation of abandoning old-fashioned memory-savings designs because there’s now a lot of memory available! -Raymond]
  20. Alexandre Grigoriev says:

    [In which case I don’t want to hear you complaining about how newer versions of Windows use more memory than older versions of Windows – they’re just following your recommendation of abandoning old-fashioned memory-savings designs because there’s now a lot of memory available! -Raymond]

    I’m sure you heard some complaints from me, some of them a few times, but I never complained about newer versions using more memory. When MinWin (or WinMin?) was demoed and people were getting excited about the kernel taking 20 MB or so, I thought: “So what? The whole System32Drivers is about that size, and it’s not all loaded anyway”.

    The problem with microoptimization is that it takes resources from macro-optimizations. Elaborated kludgy schemes (like superfetch or however it’s called) can give the developers browny points, but in reality they are just made at an expense of simpler things.

    For example, you want to save time to load kernel and drivers in int13 phase time. You could collect load statistics and other crap, while loading the drivers one by one. Or you could go through CurrentControlSetServices at once, open all driver binaries at once (to minimize head movement latency), and then load all binaries. If you want to get fancy, you could use FSCTL_GET_RETRIEVAL_POINTERS to sort the binary reading order for all those drivers.

    If you get really fancy, you could get the OS prebuild the image of all boot-time drivers into a single file. This is error-prone, though.

    For usermode executables, you could kludge those “optimal” prefetch schemes. Or you can take an advantage of having lots of memory, and just prefetch the whole executable (up to a reasonable limit, like 32 MB), by touching all its pages in linear fashion. If you get fancy, you could remember what other DLLs it links to, and pre-open them and pre-fetch (entirely) by touching the sections.

    Of course, when mechinical storage eventually gives way to flash, these mechanical optimizations will be obsolete.

    Obligatory complaint: Why it is when I plug an USB flash drive it always shows “Use this drive to speed up your system”? I’m not one of those 10 people using this feature. Can I make it go away?

    [Aw-right, then, when people complain, I’ll tell them to talk to you. -Raymond]

Comments are closed.

Skip to main content