lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

> > 3) Each script gets a fresh constructed copy of the namespace.
> >    Problem: It's safe and it works, but might be too slow.

> 	It is almost the third one, but there is no COPY of the namespace.
> There is another environment for each script.  Function require is redefined
> to cache the loaded file (as a function); this function is executed in each
> new environment (if required, of course).  Globals from the original env
> are inherited.  You can take a look at CGILua 5.0 alpha 3 source, file
> clmain/venv.lua.

Cool. I like the idea of caching the loaded file as a function.  And you
are caching both the "loader" and the namespace, which is even better.
More control of what happens, and no waste of work.

> I really don't know what performance you expect, but I
> think this is not too slow...

Me neither! I will take your word for it. I was just wondering how much
faster it would be if we had some magic copy-on-write, but if this is
not a concern, I would be happy to forget about it.

Now assume the require function caches both the loader and the
namespaces (and requirelib could do the same). Any ideas of what should
be the interaction of these caches with the garbage collector?
Especially when we can have static and dynamic libraries around, at the
same time.

If we adopt Edgar's GC idea, we would have references lying around in
the cache and nothing would ever be collected. Or if the caches are
weak, things might be collected too soon.

Best regards,
Diego.