From 0629601da1d163a059fa19004256961f8ecdeb78 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 12 Jun 2018 17:26:36 +0200 Subject: Move EvalState from the stack to the heap EvalState contains a few counters (e.g. nrValues) that increase quickly enough that they end up being interpreted as pointers by the garbage collector. Moving it to the heap makes them invisible to the garbage collector. This reduces the max RSS doing 100 evaluations of nixos.tests.firefox.x86_64-linux.drvPath from 455 MiB to 292 MiB. Note: ideally, allocations would be much further up in the 64-bit address space to reduce the odds of an integer being misinterpreted as a pointer. Maybe we can use some linker magic to move the .bss segment to a higher address. --- src/nix/repl.cc | 4 ++-- src/nix/upgrade-nix.cc | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nix') diff --git a/src/nix/repl.cc b/src/nix/repl.cc index f84774a53367..4723a1974b77 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -693,8 +693,8 @@ struct CmdRepl : StoreCommand, MixEvalArgs void run(ref store) override { - NixRepl repl(searchPath, openStore()); - repl.mainLoop(files); + auto repl = std::make_unique(searchPath, openStore()); + repl->mainLoop(files); } }; diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index 21892c31a893..e23ae792369c 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -118,13 +118,13 @@ struct CmdUpgradeNix : StoreCommand auto req = DownloadRequest("https://github.com/NixOS/nixpkgs/raw/master/nixos/modules/installer/tools/nix-fallback-paths.nix"); auto res = getDownloader()->download(req); - EvalState state(Strings(), store); - auto v = state.allocValue(); - state.eval(state.parseExprFromString(*res.data, "/no-such-path"), *v); - Bindings & bindings(*state.allocBindings(0)); - auto v2 = findAlongAttrPath(state, settings.thisSystem, bindings, *v); + auto state = std::make_unique(Strings(), store); + auto v = state->allocValue(); + state->eval(state->parseExprFromString(*res.data, "/no-such-path"), *v); + Bindings & bindings(*state->allocBindings(0)); + auto v2 = findAlongAttrPath(*state, settings.thisSystem, bindings, *v); - return state.forceString(*v2); + return state->forceString(*v2); } }; -- cgit 1.4.1