lua-users home
lua-l archive

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


Mike Pall wrote:
>
> There is a significant speedup for the obvious test cases. E.g.
> comparing a 100% cache miss vs. a 100% cache hit:
> 
> $ time lua-clc -e "local k; for i=1,1e7 do local function x() return i end end"
> 2.230
> $ time lua-clc -e "local k; for i=1,1e7 do local function x() return k end end"
> 0.200
> 
> But ... I don't see any kind of speedup in real-world use cases.

Well, this optimization is more to avoid creating memory trash than
to speed up closure creation.  I think, with a decent malloc a good
part of the 2 seconds are spend in the GC.

> Maybe that's because I carefully avoid creating closures in inner
> loops.

That's definitely one reason.  I do the same and I regularly frown
when I have to move a small anonymous closure to an outer scope and
give it a name.  This optimization would allow me to write the code
as it is meant to be written ;-)  But I wouldn't use it only for
inner loops but for any kind of helper functions which I normally
move outside of the using function to avoid creating it a second
time.

Another reason you see no speed up may be, that the heap is too small
or the runtime of the script is too short to produce a noticable GC
footprint.

Anyway, thanks for the implementation :-)

Ciao, ET.