lua-users home
lua-l archive

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


Feel free to provide the benchmark results next time you talk about
performance here, many people will simply ignore your comments
otherwise (I assume you benchmarked that thing, otherwise you would
have no way to predict it's "MUCH slower").

Fair. see below.

A dozen lines for every small feature, and in the end you get a
multi-gigabyte bloatware. I guess the authors have to plainly ignore
some feature request to keep Lua small.

I wouldn't want such hacks to be included in core. One of the best things
about Lua core is that it is simple enough so that I can understand the code
and make required change myself. Most of the time. Putting all the
small hacks into core would make it indecipherable.
I was asking this question to make sure I've not overlooked something,
and to possibly hear if someone has done similar modification previously.
Sorry for witing in such a way that my intent was not clear.

==8<========================

require "socket"

local N = 1000000
local reg = {}
local obj = {}
setmetatable(reg, { __mode = "k" })

local setfe = debug.setfenv
local getfe = debug.getfenv

local t = 0
local function time()
    local t2 = socket.gettime()
    print(t2 - t)
    t = t2
end

for i = 1,N do obj[i] = newproxy() end
collectgarbage()
collectgarbage()

t = socket.gettime()

for i = 1,N do setfe(obj[i], obj) end
time()

for i = 1,N do reg[obj[i]] = obj end
time()

for i = 1,N do local x = getfe(obj[i]) end
time()

for i = 1,N do local x = reg[obj[i]] end
time()

==8<========================

0.13839292526245
0.3968460559845
0.10384202003479
0.1705310344696

same thing in C, using rawget/rawset:

timing 0.095036 sec
timing 0.559623 sec
timing 0.065464 sec
timing 0.205189 sec

... also note that pure lua_setfenv doesn't allocate resources and cannot throw, thus there is no need to put it in try/catch guards at C side.