Skip to content

Instantly share code, notes, and snippets.

@catwell
Created June 22, 2012 08:21
Show Gist options
  • Save catwell/2971290 to your computer and use it in GitHub Desktop.
Save catwell/2971290 to your computer and use it in GitHub Desktop.
The state of MessagePack in Lua

The state of MessagePack in Lua

The new MessagePack website says that MessagePack for Lua is "coming soon". I thought it would be a good idea to make a quick recap on the state of MessagePack in Lua.

The historical implementation of MessagePack is mplua by Nobuyuki Kubota. It is the implementation linked from the MessagePack wiki. However, it is rather old (no updates for two years) and not very fast.

A bit less than a year ago I had to use MessagePack in LuaJIT and I wrote a FFI-based binding on the official C interface of MessagePack. I had to include a small C library that had to be compiled to wrap inline functions in the interface.

I did not like that design and it had performance issues in real use cases, mostly because I had to use calls that break the JIT mode in LuaJIT. I decided to re-implement MessagePack directly in LuaJIT with no calls to any external library but still using FFI ctypes. I called it luajit-msgpack-pure. This is the implementation I have been using to this day, it is a good solution for LuaJIT.

Starting from my code base, the awesome Kengo Nakajima ported it to pure Lua (5.1) -> lua-msgpack. His implementation is slower than luajit-msgpack-pure, mostly because there is no way to make a buffer as efficient as with FFI ctypes in pure Lua (EDIT: François Perrad proved this wrong).

Dissatisfied with the speed, he wrote lua-msgpack-native which uses a C library. I think this is probably the fastest implementation of MessagePack for any Lua platform as of now. It targets Luvit and can apparently also work with LuaJIT. I am not sure about PUC Lua (5.1, 5.2?).

A similar implementation is Salvatore Sanfilippo's lua-cmsgpack. It was originally written for the Redis project. It is a single self contained C file with no dependencies and targets Lua 5.1.

So, to sum things up:

Regarding Lua 5.2: I don't now. I plan to try to make luajit-msgpack-pure compatible with Lua 5.2 + luaffi someday, it should not be too hard. Ping me if you need this! It is probably not too hard to port lua-cmsgpack to Lua 5.2 either.

@catwell
Copy link
Author

catwell commented Nov 12, 2012

@daurminator Sorry I didn't answer you. For lua-msgpack-native as I wrote in the gist I don't know. Regarding d'Arc it is definitely not something I would use in a library.

@xpol
Copy link

xpol commented Jul 10, 2015

The module names has ran out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment