diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-04-17 23:15:34 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-04-17 23:17:21 +0200 |
commit | 69cb9f7eeef967ed80a6e75388e488361310f115 (patch) | |
tree | 0708136230482df48cb656d0f594040c53c191bc /src | |
parent | aaa109565e4fb662e423f23bc48c9ad9831dd281 (diff) |
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.)
Diffstat (limited to 'src')
-rw-r--r-- | src/nix/flake.cc | 14 |
1 files changed, 14 insertions, 0 deletions
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<SQLiteTxn> 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<SQLiteTxn>(state->db); + } + + ~AttrDb() + { + try { + auto state(_state->lock()); + state->txn->commit(); + state->txn.reset(); + } catch (...) { + ignoreException(); + } } AttrId setAttr( |