Checking out the Linux kernel in under a second #349
Byron
started this conversation in
Show and tell
Replies: 2 comments 15 replies
-
Off topic, but how in the world did you achieve this? M1? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes, an M1 Pro. This machine is certainly a factor but I expect other computers to achieve the same.
|
Beta Was this translation helpful? Give feedback.
15 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here we will explore how to increase the speed when checking out a repository using the Linux kernel as popular and well-known example. We will see how fast we can go with
git
itself and then transition to an early implementation provided bygitoxide
while trying to make it as comparable as possible while pointing out the differences.Tl;dr
On
tmpfs
, one can now checkoutv5.16
of the Linux kernel in ~874ms, which equals more than 85k files/s and 1.2GB/s on a machine with 8hpc/2ec on MacOS 12.gix
, the plumbing binary ofgitoxide
, is 1.8 times faster thangit
with multi-threaded checkout (even though it's not a perfect apples to apples comparison, see Caveats).Here is the results measured on a 10 core MacBook…
…with 10 cores…
…and with a single core… .
Take a look below the fold at the very bottom of the document for another table showing results of checking out on a real file system -
gix
will do that in ~3.3s andgit
takes 4.6s. There you also find instructions for how to repeat the test on your system.Bonus:
gix
on even more powerful CPUs with 10-core limitFor details of the runs, see this comment and this one.
What is 'efficiency¹'?
This value measures the effective scaling and the difference between 100% and the actual value would be waste.
If a single core finishes the task in X time, then N cores should finish in X/N time if they would scale perfectly.
The percentage is calculated using
<files/s measured for N> / (<files/s measured for 1> * N)
.N is 8.5 (8HP cores + (2E cores * 0.25).
What is a 'checkout'?
git
will create an index from a tree if none is present and use the in-memory index to checkout files. From what I can see, it will always check for existence of the file prior to writing it usinglstat
as it uses this as part of its collision detection mechanism along with change detection. Once a file is written, anotherlstat
call is issued to update that information in the in-memory index. Finally, the in-memory index is written back to disk.git
pays great attention to not allow symlinks in the path of a file that is being checked out nor will it write through a symlink. Additionally it will track collisions on file systems that are case-sensitive or have other folding rules for that matter.Caveats
gitoxide
in its current very specialized implementation namedcheckout-exclusive
requires the target directory is empty and fully under its control, hence the-exclusive
suffix, a situation that would be present for initial clones. It needs an index to be present and will not write the updated in-memory index back to disk, thus it does less work thangit
. It does, however, pay the same attention to correctness as git does, and detects collisions while avoiding to write through symlinks.Creating an index from the tree at
v5.16
of the linux kernel appears to take 200ms (time git read-tree HEAD
), and is something that typically doesn't have to be done as an existing index is used. It's something we do in our tests to forcegit
to actually perform the full checkout. Writing the index back with a single thread seems to take 40ms usingtouch a && time git add a
with a single thread. Ifgitoxide
were to perform all these operations (none of which are implemented) equally well one would have to add ~240ms to the results. Having marked a sub-second checkout time for the linux kernel I will be hard pressed to assure to stay sub-second even when these operations are done.Special Thanks
sub-second
headline you see here now. Previously I planned to get to less than 2 seconds only. Additionally thegit
invocation withhyperfine
was provided by him and was used just like that. Oh, and he is the reason you can read those tables, there were much more complicated before. Thank you!hyperfine
, an indispensable tool to run benchmarks and comparisons, and sometimes it can help reproduce race conditions, too.Reproduction and Measurements
Setup
Initial State
The exact version of
gix
used here is at 3f28e20 , and can be installed like so:On MacOS, the
tmpdisk
program can be used to create a tmpfs file system in memory.Measurements
All scripts that follow assume to start out in the
linux
clone created as the initial state.git
10 cores on tmpfs
1 core on tmpfs
1 core on APFS/SSD
10 cores on APFS/SSD
gitoxide
10 cores on tmpfs
1 core on tmpfs
1 core on APFS/SSD
10 cores on APFS/SSD
Appendix
Checking out on APFS/SSD
Beta Was this translation helpful? Give feedback.
All reactions