From 2dd715ef0b0bf3a009c11fd788930d019a9b1460 Mon Sep 17 00:00:00 2001 From: Graham Dennis Date: Wed, 21 Feb 2024 18:40:34 +1100 Subject: [PATCH] Faster flake.lock parsing This PR reduces the creation of short-lived basic_json objects while parsing flake.lock files. For large flake.lock files (~1.5MB) I was observing ~60s being spent for trivial nix build operations while after this change it is now taking ~1.6s. (cherry picked from commit 7fd0de38c6e2c203e3f3c376dcf9a48424d216fe) (cherry picked from commit f94fb636c000fa9e77d3c81c138c2e187b20368c) --- src/libexpr/flake/lockfile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index a74e68c9c..ada7cdd07 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -89,7 +89,7 @@ LockFile::LockFile(const nlohmann::json & json, const Path & path) std::string inputKey = i.value(); auto k = nodeMap.find(inputKey); if (k == nodeMap.end()) { - auto nodes = json["nodes"]; + auto & nodes = json["nodes"]; auto jsonNode2 = nodes.find(inputKey); if (jsonNode2 == nodes.end()) throw Error("lock file references missing node '%s'", inputKey);