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.)
This commit is contained in:
Eelco Dolstra 2020-04-17 23:15:34 +02:00
parent aaa109565e
commit 69cb9f7eee

View file

@ -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(