From cb90e382b5b6e177ea902b3909fd1897643ae3cd Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 5 Jan 2020 16:21:34 +0100 Subject: [PATCH] Hide FunctionCallTrace constructor/destructor This prevents them from being inlined. On gcc 9, this reduces the stack size needed for nix-instantiate '' -A texlive.combined.scheme-full --dry-run from 12.9 MiB to 4.8 MiB. --- src/libexpr/eval.cc | 4 +--- src/libexpr/function-trace.cc | 17 +++++++++++++++++ src/libexpr/function-trace.hh | 14 ++------------ 3 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 src/libexpr/function-trace.cc diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 6539a346a..1c787645d 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1106,9 +1106,7 @@ void EvalState::callPrimOp(Value & fun, Value & arg, Value & v, const Pos & pos) void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & pos) { - std::unique_ptr trace; - if (evalSettings.traceFunctionCalls) - trace = std::make_unique(pos); + auto trace = evalSettings.traceFunctionCalls ? std::make_unique(pos) : nullptr; forceValue(fun, pos); diff --git a/src/libexpr/function-trace.cc b/src/libexpr/function-trace.cc new file mode 100644 index 000000000..af1486f78 --- /dev/null +++ b/src/libexpr/function-trace.cc @@ -0,0 +1,17 @@ +#include "function-trace.hh" + +namespace nix { + +FunctionCallTrace::FunctionCallTrace(const Pos & pos) : pos(pos) { + auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); + auto ns = std::chrono::duration_cast(duration); + printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count()); +} + +FunctionCallTrace::~FunctionCallTrace() { + auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); + auto ns = std::chrono::duration_cast(duration); + printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count()); +} + +} diff --git a/src/libexpr/function-trace.hh b/src/libexpr/function-trace.hh index 2c39b7430..472f2045e 100644 --- a/src/libexpr/function-trace.hh +++ b/src/libexpr/function-trace.hh @@ -9,17 +9,7 @@ namespace nix { struct FunctionCallTrace { const Pos & pos; - - FunctionCallTrace(const Pos & pos) : pos(pos) { - auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); - auto ns = std::chrono::duration_cast(duration); - printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count()); - } - - ~FunctionCallTrace() { - auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); - auto ns = std::chrono::duration_cast(duration); - printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count()); - } + FunctionCallTrace(const Pos & pos); + ~FunctionCallTrace(); }; }