Skip to content

Depend on struct instead of lpack #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2014
Merged

Depend on struct instead of lpack #35

merged 1 commit into from
Jun 23, 2014

Conversation

ntd
Copy link
Contributor

@ntd ntd commented Jun 21, 2014

The struct module is actually available either for Lua 5.1 and 5.2.
lpack was the only dependency preventing lua-websocket to be compiled
for Lua 5.2.

The struct module is actually available either for Lua 5.1 and 5.2.
lpack was the only dependency preventing lua-websocket to be compiled
for Lua 5.2.
@@ -59,15 +57,15 @@ local encode = function(data,opcode,masked,fin)
local len = #data
if len < 126 then
payload = bor(payload,len)
encoded = spack('bb',header,payload)
encoded = struct.pack('bb',header,payload)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to have struct.pack in a local, eg: local spack = struct.pack local sunpack = struct.unpack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally against it: I'd have to jump up and down to understand the code. Anyway no problems: if I have to jump, I jump.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am a bit performance paranoid. the local is for saving table accesses at spots which are supposedly run very often. sometimes i even do it for table/object methods, e.g.

#!/usr/bin/env lua
local socket = require'socket'

local s = 'hello'
local n = 10000000

print('with table access')
do
  local t1 = socket.gettime()
  for i=1,n do
    s:upper()
  end
  local dt = socket.gettime() - t1
  print('dt=',dt)
end

print('---------------------')
print('without table access')
do
  local supper = s.upper
  local t1 = socket.gettime()
  for i=1,n do
    supper(s)
  end
  local dt = socket.gettime() - t1
  print('dt=',dt)
end

On my macbook, the second variant is about 25% percent faster, even using luajit!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am aware locals in tight loops can improve performances but here it is not the case. I am also aware you have only 200 slots for locals on either standard Lua and LuaJIT. Try to run this:

local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z

I think this has more to do with habits, a bit like the correct™ indentation to adopt.

lipp added a commit that referenced this pull request Jun 23, 2014
Depend on struct instead of lpack
@lipp lipp merged commit ee8f90f into lipp:master Jun 23, 2014
@lipp
Copy link
Owner

lipp commented Jun 23, 2014

@ntd Awesome work! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants