calio / lua-capnproto

Lua-capnp is a pure lua implementation of capnproto based on luajit.
BSD 2-Clause "Simplified" License
70 stars 24 forks source link

serialization: add method to serialize without ffi.string conversion #13

Closed vavrusa closed 6 years ago

vavrusa commented 6 years ago

This adds a method serialize_cdata() that does exactly the same thing as serialize(), except it returns a pointer to FFI array and length. This is a workaround for degraded performance when the generated messages have colliding hashes when interning with ffi.string. The ffi.string generates a hash of the string by looking at the first 4B, middle 4B, and last 4B. When these are the same, it causes a hash collision with an another string. This is unfortunately not something that the caller is always able to affect, so the only workaround is to not intern at all and use the char[] directly.

The generated function has the same function signature as serialize(), except it has two returns values - pointer to the array, and the message length.