1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 19:01:16 +02:00

Make HttpBinaryCacheStore::narFromPath() run in constant memory

This reduces memory consumption of

  nix copy --from https://cache.nixos.org --to ~/my-nix /nix/store/95cwv4q54dc6giaqv6q6p4r02ia2km35-blender-2.79

from 176 MiB to 82 MiB. (The remaining memory is probably due to xz
decompression overhead.)

Issue https://github.com/NixOS/nix/issues/1681.
Issue https://github.com/NixOS/nix/issues/1969.
This commit is contained in:
Eelco Dolstra 2018-03-28 00:01:47 +02:00
parent 08ec757726
commit e87e4a60d6
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 116 additions and 3 deletions

View file

@ -77,11 +77,29 @@ protected:
}
}
void getFile(const std::string & path,
Callback<std::shared_ptr<std::string>> callback) override
DownloadRequest makeRequest(const std::string & path)
{
DownloadRequest request(cacheUri + "/" + path);
request.tries = 8;
return request;
}
void getFile(const std::string & path, Sink & sink) override
{
auto request(makeRequest(path));
try {
getDownloader()->download(std::move(request), sink);
} catch (DownloadError & e) {
if (e.error == Downloader::NotFound || e.error == Downloader::Forbidden)
throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, getUri());
throw;
}
}
void getFile(const std::string & path,
Callback<std::shared_ptr<std::string>> callback) override
{
auto request(makeRequest(path));
getDownloader()->enqueueDownload(request,
{[callback](std::future<DownloadResult> result) {