From 8513ef64573de2ae6ad700fcca17f5459f1cea41 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sun, 20 May 2018 20:08:19 +0200 Subject: [PATCH] Do not emit import-syntax forms when no syntax forms are exported This avoids importing and re-importing the same basic modules over and over again in an eval expression (as typically, one tends to import scheme and chicken.base, which provide quite large environments, which exacerbates the problem). This also exposed a minor problem with the types-db-consistency test: It didn't import all required modules, but they were available at the toplevel due to imports done implicitly in import libraries of those modules it _did_ import. This should mitigate #1457 somewhat. Of course, if the user imports several libraries that have lots of imports and at least one syntax export, it will still be slow (as this doesn't fix the underlying quadratic behaviour), but it should be nowhere near as bad as it was before this patch. As an added bonus, this should also increase compile times for any code, because those evaluated imports will always run inside the compiler when loading the import libraries, regardless of whether the output program is static or dynamic. For compiling CHICKEN itself this makes little difference (due to -explicit-use), but for a simple program that only does (import parley), compilation time dropped from 1.5s to 0.8s (with a DEBUGBUILD). Startup time of csi also improves dramatically: csi -e '' takes 0.024s after this patch versus 0.30s before (both with a DEBUGBUILD). --- modules.scm | 12 +++++++++--- tests/types-db-consistency.scm | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules.scm b/modules.scm index f0bf4a3d..81bef7da 100644 --- a/modules.scm +++ b/modules.scm @@ -310,9 +310,15 @@ (ifs (module-import-forms mod)) (sexports (module-sexports mod)) (mifs (module-meta-import-forms mod))) - `(,@(if (pair? ifs) `((scheme#eval '(import-syntax ,@(strip-syntax ifs)))) '()) - ,@(if (pair? mifs) `((import-syntax ,@(strip-syntax mifs))) '()) - ,@(##sys#fast-reverse (strip-syntax (module-meta-expressions mod))) + `(,@(if (and (pair? ifs) (pair? sexports)) + `((scheme#eval '(import-syntax ,@(strip-syntax ifs)))) + '()) + ,@(if (and (pair? mifs) (pair? sexports)) + `((import-syntax ,@(strip-syntax mifs))) + '()) + ,@(if (pair? sexports) + (##sys#fast-reverse (strip-syntax (module-meta-expressions mod))) + '()) (##sys#register-compiled-module ',(module-name mod) ',(module-library mod) diff --git a/tests/types-db-consistency.scm b/tests/types-db-consistency.scm index 5bfb89ba..5f1a255b 100644 --- a/tests/types-db-consistency.scm +++ b/tests/types-db-consistency.scm @@ -7,6 +7,8 @@ (chicken read-syntax) (chicken irregex) (chicken memory) + (chicken port) + (chicken process-context) (chicken process-context posix) (chicken tcp) srfi-4) -- 2.11.0