Monday, October 03, 2005

CCleaner Cripples Application Load Times

Recently CCleaner has added an internet urban legend as a cleaning option, "Old Prefetch data". Cleaning the Prefetch folder is an internet Myth that simply will not die due to the gross ignorance of many people in regards to how Windows XP Prefetching works. These same people generally recommend other bogus advice such as disabling Windows Prefetching completely and adding /Prefetch:1 to desktop shortcuts.

"Bottom line: You will NOT improve Windows performance by cleaning out the Prefetch folder. You will, in fact, degrade Windows performance by cleaning out the Prefetch folder." - Source

CCleaner for the most part is a good application, it quickly and easily removes temporary and unused files from Windows. It has a nice interface that clearly shows what has been "cleaned". On neglected systems this can free hundreds of Megabytes of harddisk space. Apparently in the authors quest to clean everything and anything, he blindly ignored how Prefetching works.

Prefetching
"When a Windows XP-based system is booted, data is saved about all logical disk read operations. On later boots, this information is used to pre-fetch these files in parallel with other boot operations. During boot and application launch, a Windows system demands and pages a sizable amount of data in small chunks (4K to 64K), seeking between files, directories, and metadata. The Logical Prefetcher, which is new for Windows XP, brings much of this data into the system cache with efficient asynchronous disk I/Os that minimize seeks. During boot, the logical prefetcher finishes most of the disk I/Os that need to be done for starting the system in parallel to device initialization delays, providing faster boot and logon performance.

Logical prefetching is accomplished by tracing frequently accessed pages in supported scenarios and efficiently bringing them into memory when the scenario is launched again. When a supported scenario is started, the transition page faults from mapped files are traced, recording which page of a file is accessed. When the scenario has completed (either the machine has booted or the application started), the trace is picked up by a user-mode maintenance service, the Task Scheduler. The information in the trace is used to update or create a prefetch-instructions file that specifies which pages from which files should be prefetched at the next launch.

The user-mode service determines which pages to prefetch by looking at how successful prefetching has been for that scenario in the past, and which pages were accessed in the last several launches of the scenario. When the scenario is run again, the kernel opens the prefetch instructions file and asynchronously queues paging I/O for all of the frequently accessed pages. The actual disk I/Os are sorted by the disk drivers to go up the disk once to load all pages that are not already in memory. This minimizes seeks, cuts down on disk time, and increases performance. The kernel also prefetches the file system metadata for the scenario, for example, MFT entries and directory files. Because prefetching is useful only when the required data is not in memory, the applications that are launched frequently are not traced and prefetched each time." - Source

Prefetching Facts
1. Prefetching is enabled by default in Windows XP.
2. Prefetching is configured optimally by default.
3. Prefetching will significantly improve application load times.
4. The Prefetch (.pf) files are not a cache, they are reference files.
5. The Prefetch (.pf) files do not preload/cache anything upon Windows startup that does not normally load at startup.
6. Only one Prefetch (.pf) file is referenced during startup = NTOSBOOT-B00DFAAD.PF
7. Only one Prefetch (.pf) file is created per application.
8. The Prefetch (.pf) files including the Layout.ini and NTOSBOOT-B00DFAAD.PF files are automatically updated.
9. The Prefetch folder is auto cleaned after 128 entries have been reached down to the 32 most used applications.
10. Notebooks running on battery power will not execute idle tasks and thus cannot further optimize or remove prefetch files.

What CCleaner does
CCleaner deletes any Prefetch file older then two weeks based on the .pf file's last access date. This is completely idiotic for a number of reasons. First you should never delete a .pf for any installed application. With the .pf file missing, that application will take up to 100% more time to load when you decide to launch it. CCleaner does this to any application you have installed on your computer but have not used in over two weeks. It makes absolutely no sense to delete these files. Why would you deliberately want to slow down any installed application's load time? It will also do this if you have not used you computer for two weeks. Second, it is quite common to disable the NTFS Last Access Time Stamp for performance reasons. I actually recommend doing this since it speeds up the file system. In this case CCleaner will delete any .pf file that was created over two weeks ago. You can clearly see how running CCleaner in this case would wind up deleting ALL your Prefetch files every two weeks. Now you are crippling every application's load time on your system instead of just the ones you have not used in two weeks. Ridiculous!

Testing
Make sure the Task Scheduler service is set to automatic. Launch an application like Firefox three times. Reboot and make sure there is a FIREFOX.EXE-XXXXXXXX.pf file in the C:\WINDOWS\Prefetch folder. If there is, launch Firefox and time it. Then delete the .pf file, reboot, relaunch Firefox and time it again. You will now see Firefox take a significantly longer time to load. Now imagine this on any other application, then imagine doing this deliberately every two weeks? Why? To save a tiny bit of HD space? It makes no sense. 128 .pf files take up maybe 5 MB of disk space.

Conclusion
Do not clean the prefetch folder! If you use CCleaner uncheck the "Old Prefetch data" option. Finally let the makers of CCleaner know they need to remove this option from CCleaner.

References
Windows XP: Kernel Improvements Create a More Robust, Powerful, and Scalable OS - (Mark Russinovich, Ph.D Computer Engineering, Microsoft Technical Fellow)
Misinformation and the The Prefetch Flag - (Ryan Myers, Microsoft Windows Client Performance Team)
One more time: do not clean out your Prefetch folder! - (Ed Bott, Author Windows Inside Out)
Kernel Enhancements for Windows XP - (Microsoft)
Benchmarking on Windows XP - (Microsoft)
Microsoft Windows XP Performance - (Microsoft)


Update, October 4, 2005:
It has been brought to my attention the makers of CCleaner want to cover up and ignore this issue. They do not want to allow a discussion of it because they know they are wrong and cannot win an argument where the facts are against them. They either delete any topics in their forums brought up about the issue, lock them or ban the users who bring it up. I recommend instead to bring this issue up in all forums where they will allow the discussion and you can inform people of how prefetching works and why CCleaner should have the "Old Prefetch data" option removed.

Update, August 12, 2006:
CCleaner v1.32.345 has moved the "Old Prefetch data" option to the advanced section and now it is not selected by default. However there should still be a warning added when you select it. And of course it is still not recommended to use this option for any reason as it is still useless and will do nothing but slow down your system. But at least this is an improvement and should prevent many users from unknowningly slowing there system down everytime they run CCleaner.

6 comments:

Andrew said...

For the Prefetch files to become corrupted in the NTFS file system is very rare and a sign that something else is wrong. No file should just become corrupted. This article deals with Disk Imaging AND Slow Boot Times. This relates to corporate environments that deply systems through Images and a specific problem that can develop. This is one of many problems that can develop if Disk Imaging goes wrong. It has no relation to the average end user or CCleaner.

Once the source of the File Corruption is fixed, there would be no reason to do this ever again. But I would not trust any image with corrupt files and simply reimage or create a new image to be used.

By default the Prefetcher will not corrupt Prefetch files on a working system.

Andrew said...

Response to ye_olde_jp

"2. If you're suggesting that anything by MS is actually configured optimally, you haven't dealt with them long enough!"

I have dealt with Microsoft products since DOS 3.0. Prefetching is configured optimally by default. If you think otherwise it is because you simply do not understand how it works.


"4. True for the most part, but a reference is still made - essential for anything that gets cached"

No they are reference files PERIOD. Nothing is cached. They are not a cache and have nothing to do with caching. Nothing is preloaded before the application load is initiated.


"5. True (in theory)"

No BY DESIGN! Code does not work in theory, it either works or it does not and it only works one way - the way it was programmed.


"6. Depends on your flavour of Windows: this is _supposed_ to be true:"

Flavor? Prefetching only works on Windows XP and it works the same for all retail versions.

"I have seen too many instances of otherwise"

Really? Where have you seen this? Provide ONE piece of evidence where a separate prefetch file was created for an application that launched from the exact same executable and file location. The only time a separate Prefetch file would be created for the exact same executable in the exact same location is if someone foolishly used the useless /prefetch switch.


"7. True (again, in theory)"

No this is by design. Again you use incorrect assumptions. Go talk to the Microsoft Performance Team.


"8. Really? You mean it actually does this?? Then how do I explain to my customers that the 300+ entries they have are really just a figment of their imagination?"

Easy.

1. They have Prefetching disabled in some way. Either Windows was installed from a nlite style version with components ripped out or default settings changed. Or They (or someone for them) irresponsibly disabled the Task Scheduler or Registry Values relating to prefetching such as 'EnablePrefetcher'. Or they ran a useless 'Tweaking' application that changed these for them.

2. They are a notebook user and continuously run on battery power. Idle Tasks will not run on battery power and this prefetching cannot further optimize itself. You can manually force these to run with this command from start, run:

Rundll32.exe advapi32.dll,ProcessIdleTasks

I will further source the article and unless you are calling people like Mark Russonvich and the Windows Performance Team a liar, I would be careful with your claims about this. I am not talking about anything but ONE performance enhancing feature for Windows XP = Prefetching.

ye_olde_jp said...

I knew I'd get into trouble for writing a response so hurriedly!
Please allow me to explain myself :)

Firstly: thank you for updating the info on your webpage. Also, I don't normally deal with laptops/notebooks (I still think they're toys, but that's just me ;) - I know they're not, but you get my drift), but your suggestion on how to force Task Scheduler was a good reminder to me.

Secondly: I don't knock Microsoft anymore than any other OS-maker out there - past or present.
Windows is the ONLY OS I recommend and install for my customers; I, too, am unlikely to move away from the Windows platform, regardless of any issues I may encounter; it's just too easy to use for me to pass up. My only question, in regards to my next OS, is "do I go 64-bit or do I stick with 32-bit?" but will be Windows regardless. As a composer, 64-bit looks very attractive indeed (excellent ASIO drivers and an almost complete lack of latency, amongst other things), but the manufacturers of my music software are still lagging behind :/

Thirdly:
I wasn't saying that files were being cached, but merely referenced for caching. Fair enough if the way I wrote this originally may have suggested otherwise to you.
Don't worry - I'm well aware of the fact that the size of the Registry & related PFs are really negligible in terms of performance issues, though a really messed-up Registry will, obviously, be a bugger for Windows to deal with.

Fourthly: there's no way I would recommend to anyone to disable Prefetching - I know damn well how much of a difference this can make in some situations. I agree with you on almost every point regarding prefetching there. Any -one/-programme/-company that removes these PFs, or recommends you should, is simply idiotic.

Fifthly: my poor reference to 'flavour of Windows' was meant to mean Home Edition or Pro: I have encountered the problems I mentioned ONLY on Home Edition PCs and _NEVER_ on the Pro Edition. I just think that's weird, considering the very few differences between the two OSes. Off and on, I have had this discussion (aside from a number of (unrelated) other issues) with MS for more than 4 years already.
One's mileage may vary, I guess.

Lastly: the extra PFs (beyond 128 entries) I have seen on my customers' computers, were always suffixed with a number like sameprogname_1; sameprogname_2; etc. None of these machines were debilitated by my customers (I installed Windows as part of the legal requirement as an OEM for XP and the only thing I ever added was my oem.ini - everything else was left completely untouched [read: MS default installation]). Customisation is always left up to the customer, which most of my customers never bother with - they just want to get on with things, without having to bother with changing this setting or the other.


To Andrew - a bit of background info:
Please note that none of my statements are theory, but physical, reproducible, factual and actual 'problems' (as this particular issue is, in all reality, a very minor one. Performance, after all, remains virtually unchanged) - confirmed by MS over the years. The only reason I cannot quote these problems in detail on this website, is because of silly local privacy issues (I don't have my customers' express permission to do so, unless it's directed at MS themselves and not in a public forum - to do so anyway would mean legal action against me under local law, despite the fact no personally identifyable information is disclosed. Go figure. It's good to know my tax is being spent wisely..). If you have never encountered any problems with this particular feature, you have simply been fortunate - or me unfortunate; I guess it depends on how one looks at it ;) Also, please note that I don't pretend to know everything about XP; I don't. XP is simply too feature-rich! This is why I hunt around for good websites (and found this one along the way). If you feel I'm being unfair or whatever towards you, or anyone in the MS team that designed XP (and you, like me, aren't one of them either), then so be it, but was _never_ my intention. I never attack anyone personally in a public environment - to do so would be foolish and unfair.
Making a statement like "DOS 3.0", which I of course presume is MS DOS v3.0 (considering DR DOS was master and ruler of the PC universe at the time), simply means to me that you *might* be a young-un and I'm just an *old-fart*.. possibly trying to recapture my youth :P
Whatever happened to the Eighties??
A pity humans can't get upgrades.. x)

Whilst I won't elaborate on my dealings with MS (this isn't the right place for it, let's be honest, nor is there a need for it), I stand by the claims I made. Don't worry; I have been wrong on a number of occassions, which MS was very quick to point out and rightly so. I have also, unfortunately, been right on other occassions. However, with the help of other MS support people, almost anything I brought to their attention was resolved amicably and properly (but rarely quickly; in itself understandable, due to the very large(!) customer-base MS has) - leading to a satisfactory solution. This is, of course, A Good Thing.
The dealings with their PR-arm weren't so friendly, but I guess these are people that don't really concern themselves with bits-and-bytes so much, but the look of [PR] things. Programmers/Coders are far easier to deal with (and more fun)!

To be fair, only some of my issues with MS have been about this very subject of Prefetching and almost all were resolved with the help of MS support. I hasten to add, though, that there are a number of issues still unresolved (like MS hiding a programme from the add/remove section, e.g. Outlook Express, rather than actually uninstalling it, despite the fact it's a non-requirement for XP to function correctly), but these are clearly unrelated to this particular subject. Very much like my dealings with the head-honcho of AMD Australia, who seemingly only serves to harm, rather than help, AMD's reputation. Or the likes of Sony, whom I've had to threaten with legal action before they backed down.. Again, none of this is relevant to Prefetching, but might serve to give you an insight into some of the dealings I've had over the years. It wouldn't surprise me one bit if you have had similar issues with companies/individuals ;)

In a nutshell: there are definately (very minor) issues regarding Prefetching, but seem to be related to XP Home Edition only (in -my- dealings). I just wanted to see a balanced view of the 1000's of installations of XP I've done over the years, compared to those of other OEMs/Partners, where any issue(s) regarding, in this case, Prefetching, were treated correctly and fairly. Anyone using XP (of whatever 'flavour' of XP this may be), may wish to know that there are ways to ensure a stable & efficient environment, despite any problems that may occur along the way. Prefetching is just one of them and really just a minor issue at that. You, and others on your otherwise excellent website, are more than capable/willing to explain this in a way where people, like my customers, can safely turn to for the _right_ advice in order to get their Windows running as well as it can be. It is the accuracy of knowledge you display, that attracted me to this website in the first place!

Ultimately, what this all comes down to is the one constant (& inconsistent) variable - the human factor: eventually all man-made creations will fail - it is only a matter of time. This is quite natural and I don't really have a problem with it, as long as any [possible] failures are considered, mentioned and, in time, corrected. One never stops learning, I guess ;)

Happy computing!

Andrew said...

The problem with the word caching is it implies the files are stored somewhere to be accessed later. This is not true at all with prefetching and why the word cache should not be used. Prefetching is about how the files are loaded to memory. When you launch an application it will load various files from disk to RAM. The normal process can be very innefficient and jump around the disk reading in pages of file data here and there. Prefetching traces this process so that when you launch the application again these files (rather pages of data) can be optimally loaded asynchronously to RAM. Which files are loaded for what application is stored in the Prefetch trace file (.pf).

Yes of course registry issues can cause problems and errors but not performance issues due to useless or erroneous clutter.

I have read every document Microsoft has available regarding prefetching and spoken directly with the Microsoft Performance Team and never once has any issues been brought up with the Home edition. I have never seen this on any of the thousands of machines I have worked on or encounted this online before your comment.

For many years now there has been the useless /prefetch:1 tweak going around the Internet. Which if added to a shortcut's target line will create a second prefetch file for the same application. People can either manually do this or run various "tweaking" utilities that add this to certain applications. Firefox is a favorite among others.

While I believe you when you say you do not modify the systems in this way. I in no way believe it is above or beyond the possibility that the customer did. A simple resolution to confirm this would be a clean install from an original Windows XP CD.

I am aware of the various DOS versions, the specific version I had was IBM PC DOS 3.0 on an IBM AT back in the 80s. While I have used DR DOS I prefered MS-DOS - especially MS-DOS 5.0 and 6.xx

Unfortunately for me to believe any problem exists then I need to see documentation that allows reproduction of the problem - otherwise I don't believe it. If you can provide this documentation to me I would be more than willing to look at it and add any corrections that can be verified. But I have simply never seen nor heard of any problems like this and have absolutely no documentation on them. Thus it is unverifiable to me.

Thanks for taking the time to provide your insight on the issue and I have added the additional References above.

Unknown said...

Does anyone know for which applications the prefetch file is created and for which not?
I've noticed that for example it's created for ftp.exe but it's not created for calc.exe.

Thanks

Andrew said...

Windows XP creates a prefetch file for all executables but it also requires prefetching to be enabled and working properly:

The following registry key needs to be set to 3: (it is by default)

[HKLM\SYSTEM\CurrentControlSet\Control\SessionManager\MemoryManagement\PrefetchParameters] "EnablePrefetcher"

And you system needs to go idle, it will not on battery power. So laptop users need to force the idle tasks to run once a week manually: go to start, run and type:

Rundll32.exe advapi32.dll,ProcessIdleTasks