From 2d663b502da16d6dc480bff7f58297d176d04246 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 6 Aug 2011 19:45:43 +0000 Subject: =?UTF-8?q?*=20Cache=20the=20result=20of=20file=20evaluation=20(i.?= =?UTF-8?q?e,=20memoize=20evalFile()).=20=20This=20=20=20prevents=20files?= =?UTF-8?q?=20from=20being=20evaluated=20and=20stored=20as=20values=20mult?= =?UTF-8?q?iple=20=20=20times.=20=20For=20instance,=20evaluation=20of=20th?= =?UTF-8?q?e=20=E2=80=98system=E2=80=99=20attribute=20in=20NixOS=20=20=20c?= =?UTF-8?q?auses=20=E2=80=98nixpkgs/pkgs/lib/lists.nix=E2=80=99=20to=20be?= =?UTF-8?q?=20evaluated=202019=20times.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Caching gives a modest speedup and a decent memory footprint reduction (e.g., from 1.44s to 1.28s, and from 81 MiB to 59 MiB with GC_INITIAL_HEAP_SIZE=100000 on my system). --- src/libexpr/eval.hh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/libexpr/eval.hh') diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 413234f2b..694d4407b 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -211,8 +211,17 @@ private: bool allowUnsafeEquality; + /* A cache from path names to parse trees. */ std::map parseTrees; + /* A cache from path names to values. */ +#if HAVE_BOEHMGC + typedef std::map, gc_allocator > > FileEvalCache; +#else + typedef std::map FileEvalCache; +#endif + FileEvalCache fileEvalCache; + typedef list > SearchPath; SearchPath searchPath; SearchPath::iterator searchPathInsertionPoint; -- cgit v1.2.3