buffer: remove Lua registers
Lua buffer module used to have a couple of preallocated objects of type 'union c_register'. It was a bunch of C scalar and array types intended for use instead of ffi.new() where it was needed to allocate a temporary object like 'int[1]' just to be able to pass 'int *' into a C function via FFI. It was a bit faster than ffi.new() even for small sizes. For instance (when JIT works), getting a register to use it as 'int[1]' cost around 0.2-0.3 ns while ffi.new('int[1]') costs around 0.4 ns. Also the code looked cleaner. But Lua registers were global and therefore had the same issue as IBUF_SHARED and static_alloc() in Lua - no ownership, and sudden reuse when GC starts right the register is still in use in some Lua code. __gc handlers could wipe the register values making the original code behave unpredictably. IBUF_SHARED was fixed by proper ownership implementation, but it is not necessary with Lua registers. It could be done with the buffer.ffi_stash_new() feature, but its performance is about 0.8 ns which is worse than plain ffi.new() for simple scalar types. This patch eliminates Lua registers, and uses ffi.new() instead everywhere. Closes #5632
Showing
- changelogs/unreleased/fix-ibuf-static.md 7 additions, 0 deletionschangelogs/unreleased/fix-ibuf-static.md
- src/box/lua/net_box.lua 1 addition, 3 deletionssrc/box/lua/net_box.lua
- src/box/lua/schema.lua 1 addition, 1 deletionsrc/box/lua/schema.lua
- src/lua/buffer.lua 0 additions, 43 deletionssrc/lua/buffer.lua
- src/lua/crypto.lua 6 additions, 5 deletionssrc/lua/crypto.lua
- src/lua/msgpackffi.lua 27 additions, 23 deletionssrc/lua/msgpackffi.lua
- src/lua/socket.lua 7 additions, 13 deletionssrc/lua/socket.lua
- src/lua/string.lua 6 additions, 2 deletionssrc/lua/string.lua
- src/lua/swim.lua 1 addition, 1 deletionsrc/lua/swim.lua
- test/app-tap/gh-5632-gc-buf-reuse.test.lua 45 additions, 1 deletiontest/app-tap/gh-5632-gc-buf-reuse.test.lua
- test/app-tap/module_api.test.lua 1 addition, 2 deletionstest/app-tap/module_api.test.lua
- test/app/buffer.result 0 additions, 36 deletionstest/app/buffer.result
- test/app/buffer.test.lua 0 additions, 14 deletionstest/app/buffer.test.lua
Loading
Please register or sign in to comment