mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +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
|
@ -34,15 +34,14 @@ protected:
|
|||
const std::string & data,
|
||||
const std::string & mimeType) override;
|
||||
|
||||
void getFile(const std::string & path,
|
||||
Callback<std::shared_ptr<std::string>> callback) override
|
||||
void getFile(const std::string & path, Sink & sink) override
|
||||
{
|
||||
try {
|
||||
// FIXME: O(n) space
|
||||
callback(std::make_shared<std::string>(readFile(binaryCacheDir + "/" + path)));
|
||||
readFile(binaryCacheDir + "/" + path, sink);
|
||||
} catch (SysError & e) {
|
||||
if (e.errNo == ENOENT) callback(nullptr); else callback.rethrow();
|
||||
} catch (...) { callback.rethrow(); }
|
||||
if (e.errNo == ENOENT)
|
||||
throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache", path);
|
||||
}
|
||||
}
|
||||
|
||||
PathSet queryAllValidPaths() override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue