Home arrow Windows Help arrow Prefetching

Prefetching

There's a whole bunch of pages out there giving incorrect advice about how prefetching works in Windows XP and what you can do to speed it up. They say to clean out prefetch folder. This is very bad advice.

Your prefetch folder is C:\WINDOWS\Prefetch\, and it is full of files with the format [FILENAME.EXE]-[hex number].pf. There are 'helpful' sites out there telling you to delete these files, or delete only old ones, or whatever.

 This advice is stupid and counterproductive. The only reason you should ever delete files in that directory is if you're running impossibly low on disk space, and there are  plenty of better ways to clear up the six megabytes or so files in that directory take up. (Plus, files there will be recreated automatically anyway, making it rather pointless.)

But what is that directory actually for? Well, to explain that, we'll have to explain a little about how modern operating systems work. All modern OSes use a form of memory management called 'pagingpaging'. Don't worry too much about it, but basically, each program is divided into equal sized sections. Some of these sections are in memory (RAM), some have been placed in the swap file to load quickly, and some haven't been loaded yet in the first place and will need to be read from the original executable file.

When a 'page' of memory is needed which isn't in memory, it will be loaded into memory. When memory runs low, pages that haven't been used for a while will be placed in the swap file and removed from memory.

Analogy time: It's like each program is a book, and each memory page is a page in a book. And you're at a library. They're individually stored on the shelf (original program on disk), and you can have a limited number in your hands (actual memory), and you also have a table you can temporarily place them on when your hands are too full (swap file). Remember, you're grabbing each page by itself, not the whole book/program...we know that sounds weird but that's how computers work.

But, back to prefetching. Prefetching comes in when a program is first launched. Programs aren't in linear order in memory like a book. They're more like 'Choose your own adventure' books, except they eventually end up looping among a few dozen different pages. But, when starting up, they might need to run something at the start, then halfway in, then near the end, then back nearish the star, before they settle down to any pattern.

But Windows doesn't want to load whole programs into memory. It's wasteful and slow. We know in the real world we grab entire books, but computers don't. They'd have to immediately dump out half the pages onto the table because they can't hold enough. OTOH, loading them only as you need them is slow, also. You have to keep walking back to the shelves until you have all the right pages in your hands. The system works fine when you need a new page every few seconds, but quickly falls apart when you need 200 of them before the program will respond to input.

So, in this analogy, you write down, the first time you use a book, inside the front cover, a list of pages that you're going to need to start using the book. The first time is slow and annoying, but all subsequent times you can open the book and quickly grab the pages you need to start and not have to make repeated trips.

That's what those files in the prefetch folder are doing. They're a list of hints, to Windows, written by Windows, about what memory pages will be needed in the first few seconds of the program. So when you launch it, Windows can say 'Load all these pages into memory' at the very start, which is much faster than waiting until the program needs them.

It's worth mentioning that this isn't always 100% accurate...maybe you've changed your color depth since you ran the program last, or you turned off the splash screen, and that might cause something else to run during initialization, and that might result in a page being loaded that wasn't before. But it's a lot better than the alternatives of either loading nothing on program startup or loading the entire program on program startup.

So, clearing the prefetch folder erases all that data. Which means, logically, that it slows down your computer, not speeds it up, until the data is recreated. And, looky here, it doesdoes. Twice as long for the Windows desktop to appear from the login screen.yet people continue peddling this bogus advice. So don't do that.