Why does the Disk Cleanup tool’s Windows Update Cleanup take so long and consume so much CPU?

Raymond Chen

If you ask the Disk Cleanup tool to clean up Windows Update files, you may find that it takes a long time and consumes a lot of CPU. What the heck is it doing? How hard can deleting files be?

The Windows Update Cleanup option is doing more than just deleting files. It’s basically doing two things.

First, it does the equivalent of dism /Online /Cleanup-Image /StartComponentCleanup. This is a command that goes by the nickname deep clean, and it scavenges the component catalog looking for components that are no longer being referenced. Normally, the system automatically does component scavenging on a schedule maintenance task. The automatic scavenging has a policy of waiting 30 days before removing an unreferenced component, and it also has a self-imposed time limit of one hour. But the special command line above bypasses both the 30-day grace period and the 1-hour timeout. Unreferenced components are removed immediately, and the task will run to completion, even if it takes more than an hour.

(I don’t know if the one hour timeout is actually meaningful in practice. I suspect it’s there just as a backstop in case the scavenging process goes haywire.)

The other thing that the Windows Update Cleanup task does is check with the Wof­Should­Compress­Binaries function to see whether the system would benefit from compression of system files. If so, then it takes the operating system files that aren’t already compressed and compresses them, storing the result in the WofCompressedData alternate data stream, as I described some time ago.

The compression algorithm used by the Windows Overlay Filter is higher quality than a real-time compression algorithm, and it’s designed so that decompression is fast, but compression is expensive. And that’s the cost: You need to spend a lot of CPU time to do the compression, which is why the Windows Update Cleanup is using so much CPU time.

And it’s doing the expensive data compression because it’s trying very hard to free up disk space. Because that’s presumably why you are running the Disk Cleanup tool.