mirror of
https://github.com/NixOS/nix
synced 2025-06-27 00:11:17 +02:00
Make LocalBinaryCacheStore::narFromPath() run in constant memory
This reduces memory consumption of
nix copy --from file://... --to ~/my-nix /nix/store/95cwv4q54dc6giaqv6q6p4r02ia2km35-blender-2.79
from 514 MiB to 18 MiB for an uncompressed binary cache, and from 192
MiB to 53 MiB for a bzipped binary cache. It may also be faster
because fetching can happen concurrently with decompression/writing.
Continuation of 48662d151b
.
Issue https://github.com/NixOS/nix/issues/1681.
This commit is contained in:
parent
81ea8bd5ce
commit
08ec757726
6 changed files with 65 additions and 31 deletions
|
@ -311,6 +311,14 @@ string readFile(const Path & path, bool drain)
|
|||
}
|
||||
|
||||
|
||||
void readFile(const Path & path, Sink & sink)
|
||||
{
|
||||
AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
|
||||
if (!fd) throw SysError("opening file '%s'", path);
|
||||
drainFD(fd.get(), sink);
|
||||
}
|
||||
|
||||
|
||||
void writeFile(const Path & path, const string & s, mode_t mode)
|
||||
{
|
||||
AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, mode);
|
||||
|
@ -593,7 +601,7 @@ void drainFD(int fd, Sink & sink, bool block)
|
|||
throw SysError("making file descriptor non-blocking");
|
||||
}
|
||||
|
||||
std::vector<unsigned char> buf(4096);
|
||||
std::vector<unsigned char> buf(64 * 1024);
|
||||
while (1) {
|
||||
checkInterrupt();
|
||||
ssize_t rd = read(fd, buf.data(), buf.size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue