Add combined AddTempRootReturningPathInfo op to speed up nix eval#15546
Add combined AddTempRootReturningPathInfo op to speed up nix eval#15546bouk wants to merge 2 commits intoNixOS:masterfrom
nix eval#15546Conversation
|
The general idea looks good to me, but it may be better to combine this with Note that the overhead of the daemon calls is much less an issue when using the async path writer (#13798) because then the evaluator doesn't need to wait for the calls to |
|
Yup, async writing from the evaluator is definitely on the menu. Note that this can also be applied to all the other cases where we cache things client-side (like fetching sources to the store). |
|
Ah great, #13798 is exactly the next step I had in mind. I can change this PR to combine it with QueryPathInfo, it still makes the async path writer faster. |
2abc777 to
221aa20
Compare
nix evalnix eval
221aa20 to
49f7655
Compare
| } | ||
| // Fallback for older daemons: use the default implementation | ||
| // which calls addTempRoot + queryPathInfo separately. | ||
| return Store::addTempRootReturningPathInfo(path); |
There was a problem hiding this comment.
Does this work correctly? I don't use C++ often
|
@edolstra I've amended the PR to query path info instead |
49f7655 to
658c555
Compare
|
The |
658c555 to
c3b6f08
Compare
|
The tests are failing after switching to |
c3b6f08 to
a785b46
Compare
|
I've not been able to reproduce the CI failure locally, not sure how to proceed. Someone with deeper knowledge of nix internals would be more qualified to take a stab at this |
|
I get the same error as CI: I'm pretty sure you don't run those on OSX, explaining why it didn't fail in your local case. EIther way, it seems related to being able to check for validity in both the upper and lower stores and that handling needs some care. |
fbab903 to
72586ef
Compare
|
I've fixed CI, it seems my change unearthed a problem in queryPathInfoUncached. Please let me know if this fix is good |
writeDerivation() currently makes 2 separate daemon IPC round-trips per derivation: addTempRoot then isValidPath. For a NixOS system with ~8265 derivations, this adds a lot of IPC overhead. This adds a new Op::AddTempRootReturningPathInfo (opcode 48) that combines both operations into a single round-trip. writeDerivation() now uses addTempRootReturningPathInfo() which for RemoteStore uses the combined op when the daemon supports it, and falls back to sequential calls otherwise.
72586ef to
31e0d1d
Compare
|
I have talked to @xokdvium about making a write back cache store rather than introducing a bunch of new operations to accelerate eval. (See also the similar PR from Eelco.) |
Motivation
writeDerivation() currently makes 2 separate daemon IPC round-trips per derivation: addTempRoot then isValidPath. For a NixOS system with thousands of derivations, this adds a lot of IPC overhead.
This adds a new
Op::AddTempRootReturningPathInfothat combines both operations into a single round-trip. writeDerivation() now uses addTempRootReturningPathInfo() which for RemoteStore uses the combined op when the daemon supports it, and falls back to sequential calls on the same connection otherwise.Context
I was profiling the
nix evalof a big system we have and figured out thatnix eval --read-onlywas taking ~9 seconds butnix evalwas taking 20 seconds.With the help of Claude I figured out that this was caused by IPC overhead,
writeDerivationdoes two IPCs which adds up since in this case the NixOS system has +8000 derivations. On my system (Apple M3 Pro MacBook Pro, macOS 26.3.1) the overhead per IPC is about 1ms(!).This PR combines two IPCs into one, which in my case brought
nix evalfrom 20 seconds to 15 seconds, 25% faster! I think we could bring it down even more by putting the writeDerivations into a background queue or something so the eval path isn't dependent on the IPC latency, but that would be better as a separate PR.Improvement
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.