nix nar {ls,cat}: Optimize, make nix nar cat work on pipes too#14732
Merged
Ericson2314 merged 3 commits intomasterfrom Dec 8, 2025
Merged
nix nar {ls,cat}: Optimize, make nix nar cat work on pipes too#14732Ericson2314 merged 3 commits intomasterfrom
Ericson2314 merged 3 commits intomasterfrom
Conversation
By default windows doesn't allow inheriting handles anyway. These comments are just confusing at this point.
The whole NarAccessor -> listing -> lazy NarAccessor is very weird. Source can now be seek-ed over when supported, so we can support it pretty easily. Alternatively we could also make it single-pass very easily with a custom FileSystemObjectSink. It will get removed in a follow-up commit anyway.
This was lost after 2.32 while making the accessor lazy. We can restore the support for it pretty easily. Also this is significant optimization for nix nar cat. E.g. with a NAR of a linux repo this speeds up by ~3x: Benchmark 1: nix nar cat /tmp/linux.nar README Time (mean ± σ): 737.2 ms ± 5.6 ms [User: 298.1 ms, System: 435.7 ms] Range (min … max): 728.6 ms … 746.9 ms 10 runs Benchmark 2: build/src/nix/nix nar cat /tmp/linux.nar README Time (mean ± σ): 253.5 ms ± 2.9 ms [User: 56.4 ms, System: 196.3 ms] Range (min … max): 248.1 ms … 258.7 ms 12 runs
33ee395 to
c5c05e4
Compare
Ericson2314
reviewed
Dec 8, 2025
|
|
||
| GetNarBytes seekableGetNarBytes(Descriptor fd); | ||
|
|
||
| ref<SourceAccessor> makeLazyNarAccessor(const nlohmann::json & listing, GetNarBytes getNarBytes); |
Member
There was a problem hiding this comment.
BTW this should use the new listing types now that we have them (I missed them before)
Ericson2314
approved these changes
Dec 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
This (
nix nar catworking with pipes) was lost after 2.32 while making the accessor lazy. We can restore the support for it pretty easily. Also this is significant optimization for nix nar cat.E.g. with a NAR of a linux repo this speeds up by ~3x:
Context
#14273
cc @myclevorname, you might be interested in this. Do note that we still have to parse the full NAR to validate it fully. Cutting off early wouldn't be correct.
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.