pllua / pllua-deprecated

[DEPRECATED] This repository is no longer maintained. Please follow https://github.com/pllua/pllua
197 stars 16 forks source link

luajit compiler not used for trusted version #16

Closed eugwne closed 8 years ago

eugwne commented 8 years ago

Execution time is not the same for this code:

do $$
local point
point = {
  new = function(self, x, y)
    return setmetatable({x=x, y=y}, self)
  end,
  __add = function(a, b)
   return point:new(a.x + b.x, a.y + b.y)
  end,
}
point.__index = point
local a, b = point:new(1.5, 2.5), point:new(3.25, 4.75)
for i=1,100000000 do a = (a + b) + b end
print(a.x, a.y)
$$ language [pllua/plluau]
golgote commented 8 years ago

Can it be related to https://github.com/pllua/pllua/issues/17 ? Are you sure it is built with luajit ?

eugwne commented 8 years ago

I have execution time for untrusted - 0.2 seconds, trusted - 45 seconds. When I add this lines:

lua_State *luaP_newstate (int trusted) {
...
  if (trusted) {
    const luaL_Reg luaP_trusted_libs[] = {
    ...
    #ifdef LUA_JITLIBNAME
      {LUA_JITLIBNAME, luaopen_jit},
    #endif

then execution time for trusted 0.2 seconds.

Checked for luajit on windows and terra for ubuntu.

I'm not sure that luaopen_jit should be used to turn jit on and there is no other option, and if it save to give full access to jit.* table for trusted version or not. I know not much about luajit internals.

As for #17 I make builds with terra for ubuntu, everything is fine, just LUAINC->LUA_INCDIR needs to be done

golgote commented 8 years ago

Tested. I have about the same difference in execution time as you. Something is wrong...

golgote commented 8 years ago

I get this in psql

=# DO $$ if type(jit) == 'table' then print(jit.version) else print('no jit') end $$ LANGUAGE pllua;
INFO:  no jit
DO
=# DO $$ if type(jit) == 'table' then print(jit.version) else print('no jit') end $$ LANGUAGE plluau;
INFO:  LuaJIT 2.1.0-alpha
DO