~ chicken-core (chicken-5) 36be0fcef8955eec5ae19f52723e5a0bf5b6592e
commit 36be0fcef8955eec5ae19f52723e5a0bf5b6592e
Author: Peter Bex <peter@more-magic.net>
AuthorDate: Sun May 20 20:08:19 2018 +0200
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Wed May 23 22:45:40 2018 +0200
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).
Signed-off-by: felix <felix@call-with-current-continuation.org>
diff --git a/modules.scm b/modules.scm
index f0bf4a3d..73e89474 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 (or (getp mname '##core#functor) (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)
Trap