Skip to content

Make nix nar [cat|ls] lazy#14273

Merged
xokdvium merged 3 commits intoNixOS:masterfrom
fzakaria:fzakaria/issue-13944
Oct 16, 2025
Merged

Make nix nar [cat|ls] lazy#14273
xokdvium merged 3 commits intoNixOS:masterfrom
fzakaria:fzakaria/issue-13944

Conversation

@fzakaria
Copy link
Contributor

Change to lazy NAR accessor so we don't store the complete NAR object in memory.

Timing

We can see nearly a 21x speedup

fmzakari@leviathan ~/c/g/N/nix (master)> command time -f %M -- ./build/src/nix/nix nar ls /tmp/linux.nar / > /dev/null
169936

fmzakari@leviathan ~/c/g/N/nix (master)> command time -f %M -- nix nar ls /tmp/linux.nar / > /dev/null
3680616

fixes #13944

Please see the issue for the rationale.


Add 👍 to pull requests you find important.

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

Change to lazy NAR accessor

Timing
```
fmzakari@leviathan ~/c/g/N/nix (master)> command time -f %M -- ./build/src/nix/nix nar ls /tmp/linux.nar / > /dev/null
169936
fmzakari@leviathan ~/c/g/N/nix (master)> command time -f %M -- nix nar ls /tmp/linux.nar / > /dev/null
3680616
```

fixes NixOS#13944
@fzakaria fzakaria requested a review from edolstra as a code owner October 16, 2025 17:26
@github-actions github-actions bot added the new-cli Relating to the "nix" command label Oct 16, 2025
@fzakaria fzakaria requested a review from Ericson2314 October 16, 2025 22:08
Comment on lines -148 to +152
list(makeNarAccessor(readFile(narPath)), CanonPath{path});
AutoCloseFD fd = open(narPath.c_str(), O_RDONLY);
auto source = FdSource{fd.get()};
auto narAccessor = makeNarAccessor(source);
auto listing = listNar(narAccessor, CanonPath::root, true);
list(makeLazyNarAccessor(listing, seekableGetNarBytes(narPath)), CanonPath{path});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really tried to remove the std::optional from NarAccessor but it's used by RemoteFSAccessor
I think we can make RemoteFSAccessor a lot faster by also using Sink & Source and not storing the whole memory of the NAR

@fzakaria fzakaria requested a review from xokdvium October 16, 2025 22:43
@xokdvium xokdvium merged commit 64c5596 into NixOS:master Oct 16, 2025
16 checks passed
xokdvium added a commit that referenced this pull request Oct 16, 2025
I didn't catch this during the review of #14273.
This fixes that mistake.
@myclevorname
Copy link
Contributor

TYSM

Copy link
Member

@Mic92 Mic92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release note worthy?

@Mic92 Mic92 requested a review from Copilot October 17, 2025 15:23
@Mic92
Copy link
Member

Mic92 commented Oct 17, 2025

Just currious if it finds the issue...

This comment was marked as off-topic.

@Mic92
Copy link
Member

Mic92 commented Oct 17, 2025

Nope. Not this time...

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/path-hasher-a-php-implementation-of-nix-s-nar-format/71222/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-cli Relating to the "nix" command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nix nar ls and nix nar cat use twice as much memory as the archive they process

7 participants