In this article I'll be talking about a trick to make Arch Linux's package manager much faster in cases where its databases (/var/lib/pacman) have not yet found their way into the disk cache. It was inspired by a comment Vladimir made on Arch's bugtracker. Please note that this doesn't apply to SSDs or very speedy HDDs.
What's so special about pacman's databases
A characteristic of them is that they are composed of many small files. For each package in the 'sync' databases (packages that exist in Arch's repos) 2 files are stored, and in the case of the 'local' database (installed packages) 3 files are stored per package. To give you an idea, there are 12010 files inside /var/lib/pacman on the computer I'm currently typing this. :)
Alright, so you've got a few thousand files, but they are small!
The problem isn't the size of these files (around 33MiB on my desktop, without filesystem overhead). The slowdown is caused by the fact that to parse all these files, the HDD must do lots of seek operations which take some milliseconds each. Times the number of files; it adds up. Also, this delay is especially noticeable on lower RPM hard drives.
Enough preliminary talk, what's our plan of attack?!
We want to minimize the number of seeks that occur during the first time pacman's databases are accessed after boot. It would be great if the needed data could be read sequentially off of the HDD. Enter the concept of loop devices. So, what we are going to do is stick the whole /var/lib/pacman directory inside its own filesystem which will live inside a single fixed-size file.

I'm sold, show me the codes!
OK, here's what we'll do:
- Get a root shell.
- Go into /var/lib.
- Create a 100MiB file called pacman.ext3. This will hold the loop filesystem.
- Format it as ext3. (I suppose reiserfs or some other filesystem that handles small files well could be used instead during this step, but ext3 is fast enough for our purposes and very reliable.)
- Create a tarball of the pacman directory which contains the databases.
- Add a new entry for the loop filesystem to /etc/fstab.
- Mount the loop filesystem. After this, the /var/lib/pacman directory will appear empty.
- Extract the tarball from step 5, which will populate the newly created filesystem.
- Done!
Following are the commands for the above steps:
I don't like, kill it with fire!
If you decide you want to revert what has be done, the steps are:
- Get a root shell.
- Go into /var/lib.
- Create a tarball of the pacman directory which contains the databases.
- Unmount the loop filesystem. After this, the /var/lib/pacman directory will be outdated!
- Remove the entry for the loop filesystem from /etc/fstab.
- Get rid of the now outdated pacman directory.
- Extract the tarball from step 3, which will recreate the pacman directory.
- Done!
Following are the commands for the above steps:
Conclusion
That's about it. Please don't attempt this if you don't understand what it does exactly. Consider this a disclaimer. If you bork your pacman databases, you'll most likely end up reinstalling Arch. Keep this in mind!
On the other hand, the speed-up is phenomenal. On my laptop, which has a 5400 RPM hard drive, the time required to do a 'pacman -Syu' right after boot has been shrunk from 1 minute and 38 seconds to just 6 seconds. Simply amazing. :D
Other notes
There also exists a script that does the same thing more or less. I found it after I had converted my desktop machine, and it's called pacman-cage. I do like to know exactly what goes on on my system, so I don't see me using it, but you could if you want. :)