From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 1B0886EC58; Wed, 4 Aug 2021 16:57:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1B0886EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628085422; bh=s1fKHC8L8gG7wcbFFGcqIPbd2unIat9kxKGO3JeJFe0=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=I63RsbQsboxVsYAa+8vlIeI0mN6ubLLVLhYxOwOOo4GQUA1UcXXkR80zJYDpnSREf DkESR6gmWkSAKD/MZ/KmAa+gFTW58mM7lgEvMUtz1TQkWgDs/riRjxduauVoz6jqPK x1lrSH19QCfHOv1cqKMd5f6Tm+3GFCuIt0C5IOSQ= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id A537C6EC58 for ; Wed, 4 Aug 2021 16:57:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A537C6EC58 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mBHOF-0004en-9h; Wed, 04 Aug 2021 16:57:00 +0300 Date: Wed, 4 Aug 2021 16:56:58 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210804135658.zcobwyz3rjcbwunu@esperanza> References: <5bc68e715031c04ebb022c70cf4ff27c0939598c.1627024646.git.vdavydov@tarantool.org> <9dbecb42-b2c8-ff46-ef1c-c8c14f19357f@tarantool.org> <20210803154416.3zx5t4jkdyh7adhy@esperanza> <6d4d06a2-c1ea-bb3a-2b97-537d538b75e3@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6d4d06a2-c1ea-bb3a-2b97-537d538b75e3@tarantool.org> X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C36A98DBA789EBB6AE26DB9A6C1D9BF7E0182A05F538085040AA13012DA9CB2968E34467F3D775BB50F81A674D548D1D3412404C6E2C03CD46 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE758E3775C3D7FDEE4EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063781E06E36B00F36668638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D878112E6A83B364B29B4456ED09946855117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B65D56369A3576CBA5089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5F1B63CE16A2D82F1CA73E200B90720478BE7E3AECC827C9CD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D348BE83DFD8AFB1CAC73CF6CDB6ECE7D42B3FA0CCDD4231EE6AC1C214A2D04DAA7C7C4B52613E5E7231D7E09C32AA3244C38A977653B240AAC4F2D90ACDF8C2907C86C126E7119A0FEFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojeDyvyeZJDJE8CyJJBjcRQA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DC4219B08DE42DDE2268A3880A49B3110274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 13/20] net.box: rewrite send_and_recv_{iproto, console} in C X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladimir Davydov via Tarantool-patches Reply-To: Vladimir Davydov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Wed, Aug 04, 2021 at 01:06:04AM +0200, Vladislav Shpilevoy wrote: > >>> + 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. - 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 I compared performance of fiber_self vs fiber.self by running it 100M times in a loop. Here are the results over 10 runs: fiber.self : 15.279 +- 0.021 MRPS fiber_self : 15.357 +- 0.023 MRPS (fiber.self is a Lua C function) So caching function name does result in 0.5% boost. Okay, let's add aliases for the hot functions. Here's the patch I applied on top of the series: -- >From 58687162d5102ffabc42fb2ef9a561ee7b218ab1 Mon Sep 17 00:00:00 2001 From: Vladimir Davydov Date: Wed, 4 Aug 2021 16:51:06 +0300 Subject: [PATCH] net.box: add Lua aliases for perform_request and perform_async_request These two are hot functions. Let's add aliases for them to avoid a lookup in a Lua table on each call. At the same time, internal.decode_greeting is called only when a connection is established so we don't need to have an alias for it. Part of #6241 diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 9da900933fbc..ad65a3dd528f 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -18,7 +18,8 @@ local check_index_arg = box.internal.check_index_arg local check_space_arg = box.internal.check_space_arg local check_primary_index = box.internal.check_primary_index -local decode_greeting = internal.decode_greeting +local perform_request_impl = internal.perform_request +local perform_async_request_impl = internal.perform_async_request local TIMEOUT_INFINITY = 500 * 365 * 86400 local VSPACE_ID = 281 @@ -79,7 +80,7 @@ local function establish_connection(host, port, timeout) s:close() return nil, err end - local greeting, err = decode_greeting(msg) + local greeting, err = internal.decode_greeting(msg) if not greeting then s:close() return nil, err @@ -280,9 +281,9 @@ local function create_transport(host, port, user, password, callback, if send_buf:size() == 0 then worker_fiber:wakeup() end - return internal.perform_async_request(requests, send_buf, buffer, - skip_header, method, on_push, - on_push_ctx, format, ...) + return perform_async_request_impl(requests, send_buf, buffer, + skip_header, method, on_push, + on_push_ctx, format, ...) end -- @@ -301,9 +302,9 @@ local function create_transport(host, port, user, password, callback, if send_buf:size() == 0 then worker_fiber:wakeup() end - return internal.perform_request(timeout, requests, send_buf, buffer, - skip_header, method, on_push, - on_push_ctx, format, ...) + return perform_request_impl(timeout, requests, send_buf, buffer, + skip_header, method, on_push, on_push_ctx, + format, ...) end -- PROTOCOL STATE MACHINE (WORKER FIBER) --