On Sat, Nov 21, 2009 at 8:30 PM, David Brown <cloj...@davidb.org> wrote:

> On Fri, Nov 20, 2009 at 06:37:18PM +0000, Jim Downing wrote:
>
> >I might have misunderstood, but isn't the problem the same as in Java;
> >you can't know from a static analysis which classes are going to be
> >loaded?
>
> Except that Clojure will load all of them so it can bind them to the
> vars in each namespace.  Java code is usually much less dynamic, and
> makes some static analysis a lot easier.
>
> JVMs are pretty good about not loading classes until they are used, so
> I think the real problem is that the init code for each namespace
> loads all of the classes before it does anything.  If that could be
> delayed, I suspect most of the startup delay would go away.  The trick
> is figuring out how to do this without adding yet another level of
> indirection to vars.


Are you talking about binding things like String.class to vars referenced by
symbols like String? All you need for that is a flag in the var's metadata
of loaded-yet?, next to the flag that says it's a Java class and not a
normal Clojure var. The held value can just be the class's (fully-qualified)
name until there's an attempt to use it. When it's dereferenced if the flag
is set the flag is replaced by the class object and the flag cleared; the
class object is returned. Subsequently, the flag's not set so the value is
simply returned. Checking the flag is the only added step in most var
dereferences, and var dereference is already somewhat slow, so this
shouldn't cause performance problems, nor would it add "yet another level of
indirection" to anything except, temporarily, classname vars.

It wouldn't affect the other performance concern here though, that
dependency mapping could help with: trimming jars to the bare essentials to
shrink downloads and the amount of disk space Clojure apps chew up when
installed.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to