Optimizing of unused bindings defined inside a (module ...)

Asked by Derick Eddington on 2007-12-06

Are things defined inside a module form which are not exported from the module and which are not referenced by anything inside the module optimized away or collected by the GC? I'm wondering because I'm including files into module forms to control what is visible outside the module and I don't want unused things to waste memory.

Question information

Language:
English Edit question
Status:
Solved
For:
Ikarus Scheme Edit question
Assignee:
No assignee Edit question
Solved by:
Abdulaziz Ghuloum
Solved:
2007-12-07
Last query:
2007-12-07
Last reply:
2007-12-07
Best Abdulaziz Ghuloum (aghuloum) said : #1

Some bindings get optimized and thrown away; some bindings don't. It
all depends on how smart the compiler is (now and in the future).
Have you run into any problem where such bindings are actually
causing you a problem? And how many bindings are we talking about?

Controlling visibility through modules is to help the programmer
manage code complexity. It is not meant to help the compiler
optimize things away. Helping the compiler *might* translate to
sacrificing some conveniences. I don't know what's worth more at
this point.

> Have you run into any problem where such bindings are actually
> causing you a problem? And how many bindings are we talking about?

I was including files into a module form because I needed to reimplement
a few of the things defined in the files to make them work in R6RS
libraries (the files have macros referencing unexportable mutable
variables, which I turn into parameters and reimplement the code which
uses). For the first file this seemed like a fun way to not have to
modify a 3rd-party R5RS file at all, but I ended up having to change a
higher percentage of code in other files, so I went back to modifying
the original files. I thought it would be defeating the coolness of
including into a module if the old bindings were wasting memory, though
there would not have been that many of them.

Thanks Abdulaziz Ghuloum, that solved my question.

Abdulaziz Ghuloum (aghuloum) said : #4

Unused local bindings (like in a let/letrec/internal defines/etc) are usually optimized away if the compiler finds that they're not needed. Library bindings are a little bit different since the compiler cannot prove that they're not needed without doing whole program analysis, and without making the library unavailable to "eval", "environment", and such dynamic things. Meaning: when I get a "compile-stand-alone-program" procedure working, unused library bindings will be stripped out. Until then, they may stay around for a while.