[Tarantool-patches] [PATCH 13/20] net.box: rewrite send_and_recv_{iproto, console} in C

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Aug 4 02:06:04 MSK 2021


>>> +        local hdr, body_rpos, body_end = internal.send_and_recv_iproto(
>>
>> 3. Indexing 'internal' via '.' is not free. It is a lookup
>> in a hash. You might want to save internal.send_and_recv_iproto into
>> a global variable when the module loads first time and use the
>> cached value. Non-cached version is a bit faster only for FFI, but
>> here you are using Lua C - cache should be good.
>>
>>> +            connection:fd(), send_buf, recv_buf, timeout)
>>
>> Another idea is to cache 'connection:fd()' result into a variable in
>> the root of create_transport() function. And update it when the
>> connetion is re-established. Although you probably move this all to
>> C later as well, I didn't reach the last commits yet.
> 
> The calling function is moved to C later in the patch set so these
> comments will become irrelevant.
> 
> Regarding caching function name (instead of accessing via dot operator),
> eventually there will be only two hot C functions that could benefit
> from this:
> 
>   internal.perform_request
>   internal.perform_async_request
> 
> I tried caching their names, but saw no performance gain at all in my
> test. I also tried removing fiber_self and fiber_clock aliases from
> net_box.lua and accessing these functions as fiber.<name> - again no
> difference.

Both can be explained by jitting. I wasn't sure if 'internal' is jitted,
but seems so. While jit works, there probably won't be any difference. Now
it is just inconsistent because you have a couple of methods cached:

	local encode_method   = internal.encode_method
	local decode_greeting = internal.decode_greeting

The commit LGTM anyway.


More information about the Tarantool-patches mailing list