Skip to content

Draft: libgit2 and tarball unpacking performance improvements - #16427

Draft
xokdvium wants to merge 4 commits into
masterfrom
git-perf
Draft

Draft: libgit2 and tarball unpacking performance improvements#16427
xokdvium wants to merge 4 commits into
masterfrom
git-perf

Conversation

@xokdvium

@xokdvium xokdvium commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Motivation

Use these 3 simple hacks to get 3x less CPU time for tarball unpacking (that's a fresh nixpkgs tarball import into a new cache):

Command being timed: "nix flake metadata file:///home/xokdvium/work/code/nix/unstable.tar.zst --refresh -vvvv"
        User time (seconds): 20.51
        System time (seconds): 0.66
        Percent of CPU this job got: 381%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:05.55
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 1087388

With this whole stack applied:

Command being timed: "result/bin/nix flake metadata file:///home/xokdvium/work/code/nix/unstable.tar.zst --refresh -vvvv"
        User time (seconds): 6.29
        System time (seconds): 0.43
        Percent of CPU this job got: 220%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:03.04
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 631872

I'll try to upstream all this stuff (patches 2 TBD and fix for patch 3 is up in libgit2/libgit2#7366). Draft for now because obviously we won't be patching libgit2.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

See the comment for reasoning. Re-validiating all objects we
read is probably out of scope for nix, just to catch occasional
odb corruption.
Will be upstreamed, just WIP for visibility now.
@github-actions github-actions Bot added the fetching Networking with the outside (non-Nix) world, input locking label Sep 4, 2026
@xokdvium

xokdvium commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Huh, the last patch doesn't work as expected and modifies the files on disk. One second (I guess we might as well persist it in the tarball cache maybe? But I'd prefer to set that in-memory).

…ache

This is by far the most expensive part of unpacking now:

  49.35%  nix           libgit2.so.2.0.0          [.] git_delta_create_from_index
   8.56%  nix           libgit2.so.2.0.0          [.] sha1_compression_states
   5.89%  nix           libz.so.1.3.2             [.] longest_match
   5.24%  nix           libz.so.1.3.2             [.] inflate_fast
   4.80%  nix           libz.so.1.3.2             [.] deflate_slow
   4.44%  nix           libgit2.so.2.0.0          [.] ubc_check
   1.78%  nix           libz.so.1.3.2             [.] pqdownheap.constprop.0
   1.53%  nix           libz.so.1.3.2             [.] compress_block
   1.27%  nix           libgit2.so.2.0.0          [.] git_delta_index_init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant