lipp / lua-websockets

Websockets for Lua.
http://lipp.github.com/lua-websockets/
MIT License
396 stars 113 forks source link

Rmove `struct` deps #66

Closed moteus closed 9 years ago

moteus commented 9 years ago

I just public version of frame.lua that have no deps from struct library. Also it reduce number of string.sub operation during decoding so it faster when decoding multiple frames in single packet. This is drop in replacement but it also provide new function decode_by_pos which returns position of next frame instead of rest string. It still needs more tests but this is my decode benchmark with luajit I do not make PR because this is not fully tested and this is easy run benchmarks based on websocket.frame but when I done I make PR.

>luajit frame_decode.lua
---------------------------------------
Lua  version: LuaJIT 2.0.1
---------------------------------------

Verify done
---------------------------------------
Websocket (struct)      : frame  131[b] masked 1   38[sec]     1[frame/packet] 25936[frame/sec]
Websocket (bit only)    : frame  131[b] masked 1   30[sec]     1[frame/packet] 32988[frame/sec]
Websocket (bit only/pos): frame  131[b] masked 1   30[sec]     1[frame/packet] 32888[frame/sec]
---------------------------------------
Websocket (struct)      : frame  131[b] masked 1   55[sec]   100[frame/packet] 17903[frame/sec]
Websocket (bit only)    : frame  131[b] masked 1   37[sec]   100[frame/packet] 26562[frame/sec]
Websocket (bit only/pos): frame  131[b] masked 1   30[sec]   100[frame/packet] 33123[frame/sec]
---------------------------------------
Websocket (struct)      : frame  131[b] masked 1  165[sec]  1000[frame/packet] 6048[frame/sec]
Websocket (bit only)    : frame  131[b] masked 1   72[sec]  1000[frame/packet] 13797[frame/sec]
Websocket (bit only/pos): frame  131[b] masked 1   29[sec]  1000[frame/packet] 33979[frame/sec]
---------------------------------------
Websocket (struct)      : frame  127[b] masked 0  104[sec]     1[frame/packet] 959551[frame/sec]
Websocket (bit only)    : frame  127[b] masked 0  106[sec]     1[frame/packet] 934705[frame/sec]
Websocket (bit only/pos): frame  127[b] masked 0   94[sec]     1[frame/packet] 1055595[frame/sec]
---------------------------------------
Websocket (struct)      : frame  127[b] masked 0  120[sec]   100[frame/packet] 82839[frame/sec]
Websocket (bit only)    : frame  127[b] masked 0   70[sec]   100[frame/packet] 142554[frame/sec]
Websocket (bit only/pos): frame  127[b] masked 0    7[sec]   100[frame/packet] 1265617[frame/sec]
---------------------------------------
Websocket (struct)      : frame  127[b] masked 0  918[sec]  1000[frame/packet] 10889[frame/sec]
Websocket (bit only)    : frame  127[b] masked 0  433[sec]  1000[frame/packet] 23072[frame/sec]
Websocket (bit only/pos): frame  127[b] masked 0    7[sec]  1000[frame/packet] 1254069[frame/sec]
---------------------------------------
lipp commented 9 years ago

this seems very promising!

lipp commented 9 years ago

very nice! i dont get how the "pos" variants will change things... would this introduce an (visible) API change?

moteus commented 9 years ago

There just 2 function decode and decode_by_pos. decode stay with old signature. The main benefit new function gets when you decode packet with multiple frames. Encoding is same on Lua but on LuaJIT it little faster. This benchmark is not fully true because it uses bit32 library on LuaJIT instead of its own. (I make PR to fix it tomorrow). So for testing you can just replace frame.lua and it should works.

lipp commented 9 years ago

changes are in PR #72 THX! :100: