lua-users home
lua-l archive

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


On Thu, May 21, 2020 at 10:51 AM Andrea <andrea.l.vitali@gmail.com> wrote:
LHF did mention that "This is totally different in nature from the introduction of _ENV.
While it was a simple, consistent solution, it did require some magic in the compiler: the creation of _ENV as an upvalue behind the scenes."

my question is: how much overhead in terms of bytecode space and speed does _ENV cost with respect to setfenv/getfenv?

from an historical perspective: why were getfenv/setfenv removed and substituted by _ENV? what was the advantage?

   Andrea

As far as I can tell it actually costs LESS in terms of space and complexity because it uses the standard table mechanisms instead of dedicated functions. The performance hit ought to be negligible.

The advantage is exactly the same thing: it uses the standard language mechanisms instead of poking at the function internals, and it ends up also being a little more flexible and I think a bit more elegant in the implementation. LuaJIT didn't pick it up because it's not a very compelling benefit compared to dealing with the compatibility breakage that the change introduced. The PUC-Rio team was willing to tolerate the breakage; Mike Pall wasn't.

/s/ Adam