Vladislav Shpilevoy
authored
static_alloc() appears not to be safe to use in Lua, because it does not provide any ownership protection for the returned values. The problem appears when something is allocated, then Lua GC starts, and some __gc handlers might also use static_alloc(). In Lua and in C - both lead to the buffer being corrupted in its original usage place. The patch is a part of activity of getting rid of static_alloc() in Lua. It removes it from uuid Lua module and makes it use the new FFI stash feature, which helps to cache frequently used and heavy to allocate FFI values. ffi.new() is not used, because - It produces a new GC object; - ffi.new('struct tt_uuid') costs around 300ns while FFI stash costs around 0.8ns (although it is magically fixed when ffi.new('struct tt_uuid[1]') is used); - Without JIT ffi.new() costs about the same as the stash, ~280ns for small objects like tt_uuid. The patch makes uuid perf a bit better in the places where static_alloc() was used, because its cost was around 7ns for one allocation.