lua-users home
lua-l archive

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


>For sure this solution is quite elegant. But I am afraid that performance
>is a problem. For example, the following script
>
>  a = 0
>  local i = 1
>  while i<=1000000 do
>    a = a+1
>    i = i+1
>  end
>
>runs in 1.17s in my machine. If you change it to
>
>  local a = {a=0}
>  local i = 1
>  while i<=1000000 do
>    a.a = a.a+1
>    i = i+1
>  end
>
>the time goes to 1.90s.

Presumably, adding the right instructions to lua so that it internally
reads and writes globals directly to the table would solve the performance
problem.  In a lua with globals in a table the first block of code you
wrote here would still work and the compiler would generate the
instructions to directly read and write the global table.  If the
programmer expicitly got the global table and named it something as in the
second bit of code then a slight slowdown is fine.

>Another problem is compatibility for tag methods (your "roughly"). The way
>tag methods are selected for globals is quite different from the way for
>tables.

I guess the trick here is to preserve backward compatibility but removing
this different method for tag selection would make Lua simpler internally
(perhaps).

Russ