Skip to content

Speedup nixos package count #817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2024
Merged

Speedup nixos package count #817

merged 2 commits into from
Apr 29, 2024

Conversation

xoltia
Copy link
Contributor

@xoltia xoltia commented Apr 28, 2024

I have made a couple of changes to the package counting for Nix.

  • Instead of using a shell script, I reimplemented it in C which gives me the same results in slightly lower time.
  • We can use nix-store --query --hash to check if there have been any changes before using query to count the packages. This is much faster when the cache is a hit.

Cached time vs time to query normally:

Benchmark 1: ./fastfetch
  Time (mean ± σ):      67.7 ms ±   2.2 ms    [User: 27.2 ms, System: 30.4 ms]
  Range (min … max):    63.5 ms …  72.3 ms    43 runs
 
Benchmark 2: ../../fastfetch-cli/fastfetch/build/fastfetch
  Time (mean ± σ):     323.7 ms ±  11.0 ms    [User: 125.5 ms, System: 122.8 ms]
  Range (min … max):   311.8 ms … 341.4 ms    10 runs
 
Summary
  ./fastfetch ran
    4.78 ± 0.22 times faster than ../../fastfetch-cli/fastfetch/build/fastfetch

@CarterLi
Copy link
Member

I don't use nix. I just trust your code

@CarterLi CarterLi merged commit 882b178 into fastfetch-cli:dev Apr 29, 2024
13 checks passed
@nonetrix
Copy link

nonetrix commented May 1, 2024

Great work, will be switching over to Fastfetch because of this just hoping it gets merged into nixpkgs unstable soon. 30ms does still seem a little slow compared to Arch for example but MUCH better than it was before, but is the any more room to reduce it further? I wish I could just cache the result and only update it when the system is rebuilt to be honest. For now a flake.nix file would be great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants