Skip to content

A small tip if you compile from AUR!

Just discovered this while browsing the wiki today.

You can install ccache and configure makepkg to speedup compilation times greatly!

  • sudo pacman -S ccache

  • sudo nano /etc/makepkg.conf and uncomment ccache from this line:

BUILDENV=(fakeroot !distcc color ccache check !sign)

  • uncomment and edit the MAKEFLAGS to reflect your CPU threads, for example an 8 threads (4 cores) Skylake CPU:

MAKEFLAGS="-j8"

  • Add this to your .bashrc to enable for command line compilations:

export PATH="/usr/lib/ccache/bin/:$PATH"

I went from 1 hour full kernel compilation to 17 minutes!

Source 1

Source 2

153 points46 comments
Open on Reddit
About this post
Posted
Archived
Score
153 · 100% up
Kind
Text
ID
6vez44

Author

65
posts
117
comments
18
media
View profile

47 comments

You can also change PKGEXT=".pkg.tar.gz" to PKGEXT=".pkg.tar"

in your /etc/makepkg.conf

For smaller packages this is the longest part of installing a package from the AUR. The files will of course be bigger then.

56 points

I've found this helps a ton with larger packages as well, like chrome and icon themes. It's been more than an 10x speedup in some cases where there isn't a ton of compilation.

6 points

Yes, you're totally right. It makes a very big difference with big packages too, especially with binary packages!

1 points

.tar.lzo is a nice compromise so packages still compress extremely fast, but won't take up that much space for easily compressed content.

5 points

Or just set that when you make the package.

2 points

Sure you can do that too. Here is the relevant part in the Arch Wiki.

I set it in the makepkg.conf because i have a lot of space on my SSD and my /home is on my HDD and i want it for every package anyway.

4 points

Here it is in script form

FIND="PKGEXT=\'.pkg.tar.xz\'"
REPLACE="PKGEXT=\'.pkg.tar\'"
sudo perl -i -pe "s/$FIND/$REPLACE/g" /etc/makepkg.conf
1 points

What does ccache do? Obviously, your ~8x speedup is due to using 8 (virtual) threads. -j8 is the first thing I do on a fresh Arch(/Manjaro). The other is to remove 64bit from the mkfs.ext4 format options. (Windows 10 is an asshole.)

11 points

https://wiki.archlinux.org/index.php/Ccache

It's for quicker compile times for programms you compile frequently and/or take a long time to compile.

The first time you will compile a programm it will take a little longer, but after that it can reuse compiled code that hasn't changed in my limited unterstanding.

11 points

/or take a long time to compile

Nope, it only helps on recompile. The length of compile doesn't matter at all to ccache.

10 points

But, as an end user, you compile AUR packages only once. So ccache actually hurt performance here.

4 points

What does Windows 10 have to do with ext4 64bit?

3 points

When you dual boot alongside Windows, the 64bit flag will cause it to misidentify the partition and mangle it. On reboot, Arch will drop to shell an you need to fsck before it will continue.

2 points

Isn't it cpu threads + 1 so a skylake i7 should be using -j9? At least that's what's recommended by Gentoo and they should know since they compile everything.

11 points

MAKEFLAGS="-j$(( $(nproc) + 1 ))" ;)

6 points

MAKEFLAGS="-j$(( $(nproc) + 1 ))"

Just use MAKEFLAGS=-j see:

$ man make | awk '/ -j /' RS=
       -j [jobs], --jobs[=jobs]
            Specifies the number of jobs (commands) to run simultaneously.  If
            there is more than one -j option, the last one is  effective.   If
            the  -j  option  is given without an argument, make will not limit
            the number of jobs that can run simultaneously.
1 points

Ncpu+1 is great if you don't want to do anything else on your computer while it's compiling, otherwise you and the compiler are just going to be fighting over CPU time

3 points

The number is for number of threads. I think the idea is that by making one more, you can get a little extra performance while another thread is waiting on I/O. I just use 8, but I'm also not OP.

3 points

The general recommendation is to use number_of_threads or number_of_threads+1. The difference between the two should be negligable in practice

3 points

Honestly hyperthreading is at a stage that you could use the number of the cores your CPU has and the result would be the same (not including other factors)

1 points

Get 32GB of ram and set your build folder to /tmp in makepkg.conf.

7 points

Isn't /tmp the default build folder?

1 points

From man:

If this value is not set, packages will, by default, be built in subdirectories of the directory that makepkg is called from.
5 points

idk what the default for new installs is now (aka is tmp a regular partition or tmpfs) but the point is to compile on a tmpfs partition and have enough ram so it never has to use swap

2 points

I always do the build on ram so ccache doesn't help much. If there are many differences between versions, there are many misses makeing the building last even longer. Maybe I can try syncing the cache with a cache folder in ram but this is too much trouble for a kernel compile.

5 points

Even if you build in RAM, ccache will help by saving cpu cycles.

3 points

How do you build on ram? Is that connected to setting the build directory to /tmp at all?

2 points

I guess you can also do it this way or configure your aur helper to do it.

Personally I use cower, it downloads the files of the package and puts them in a folder in which you can build it. Before I download the package I go to the /tmp directory.

3 points
unknown author

Deleted before we saved it.

1 points

Here's two snippets that you can use in a script or paste to the shell to change /etc/makepkg.conf to reflect your recommendations, so then all you would need to do is add that one line to your bashrc/zshrc

BUILDENV:

FIND=" \!ccache "
REPLACE=" ccache "
sudo perl -i -pe "s/$FIND/$REPLACE/g" /etc/makepkg.conf

MAKEFLAGS:

FIND="#MAKEFLAGS=\"-j.\""
REPLACE="MAKEFLAGS=\"-j$(nproc)\""
sudo perl -i -pe "s/$FIND/$REPLACE/g" /etc/makepkg.conf
1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.