From 08ec757726e5ef47e71bf16ed0b252b288bcf0f3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 27 Mar 2018 23:12:31 +0200 Subject: 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 48662d151bdf4a38670897beacea9d1bd750376a. Issue https://github.com/NixOS/nix/issues/1681. --- src/libstore/local-binary-cache-store.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/libstore/local-binary-cache-store.cc') diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index ae0ffa6a56ef..b7001795be4d 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -34,15 +34,14 @@ protected: const std::string & data, const std::string & mimeType) override; - void getFile(const std::string & path, - Callback> callback) override + void getFile(const std::string & path, Sink & sink) override { try { - // FIXME: O(n) space - callback(std::make_shared(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 -- cgit 1.4.1