From 69cb9f7eeef967ed80a6e75388e488361310f115 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 17 Apr 2020 23:15:34 +0200 Subject: [PATCH] Wrap eval cache creation in a giant transaction This speeds up the creation of the cache for the nixpkgs flake from 21.2s to 10.2s. Oddly, it also speeds up querying the cache (i.e. running 'nix flake show nixpkgs/nixos-20.03 --legacy') from 4.2s to 3.4s. (For comparison, running with --no-eval-cache takes 9.5s, so the overhead of building the SQLite cache is only 0.7s.) --- src/nix/flake.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 5370841ec..d311d331c 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -695,6 +695,7 @@ struct AttrDb SQLiteStmt insertAttribute; SQLiteStmt queryAttribute; SQLiteStmt queryAttributes; + std::unique_ptr txn; }; struct placeholder_t {}; @@ -726,6 +727,19 @@ struct AttrDb state->queryAttributes.create(state->db, "select name from Attributes where parent = ?"); + + state->txn = std::make_unique(state->db); + } + + ~AttrDb() + { + try { + auto state(_state->lock()); + state->txn->commit(); + state->txn.reset(); + } catch (...) { + ignoreException(); + } } AttrId setAttr(