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 5CF4A6EC55; Fri, 30 Jul 2021 01:39:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5CF4A6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627598368; bh=AIChxava8wUnRwlQ6ROY/c20dC1kbAKUgYFiHxOjw1Q=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=SlhZ6d2pO5bjkCfW7lM20Hr7sI6jc1smgOkgh+N3Vw8fyTId+TGPiQ4S3uJpoGHUi ONjoiO4HkKkAA4KKVv+Loankhlpufk+bWaHAWm5lUKdBqzovAApB/sDtAM1QJKlqrR XdbWZ8sjbAr6RP9rKuIOtSHqA3iI9abq7bQ1gpxQ= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (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 2BA7E6EC55 for ; Fri, 30 Jul 2021 01:39:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2BA7E6EC55 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1m9EgQ-0006oL-S5; Fri, 30 Jul 2021 01:39:19 +0300 To: Vladimir Davydov , tarantool-patches@dev.tarantool.org References: <6c3509125f24f6276be678d6b8f1ac264631d048.1627024646.git.vdavydov@tarantool.org> Message-ID: Date: Fri, 30 Jul 2021 00:39:17 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <6c3509125f24f6276be678d6b8f1ac264631d048.1627024646.git.vdavydov@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C36A98DBA789EBB6AE26DB9A6C1D9BF7E0182A05F538085040E1E333FC200212650B59F2A7B712F92D4741742E99D5BE57D89D5E9BEEE439AA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B4D64F1449264784EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CB87E27B59CE093D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D83FBC4C57298BAC80B66CAA9AB0108B5B117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCEA77C8EAE1CE44B0A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520B1593CA6EC85F86DF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B08F9A42B2210255C75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505799D5D3243E1C977F5DB493767CFE91F X-C1DE0DAB: 0D63561A33F958A599BD803E80DB293EC3EA0908024830C704CC3B8AA68C6D10D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753530422897FB34C3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D95739AEDB3821B487774F5BFF40EFF0ECCC4886D69A3DA0F7BA1E128A9795A76B8658A0ADD624D71D7E09C32AA3244C8A0FE28265990B3FBE21937083D8F37305AB220A9D022EBC729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojPp/mPgZxawENTMhpTFtFBQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D5543E20E5DA01F51EB535364363B44483841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 11/20] net.box: rewrite response decoder 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! See 3 comments below. On 23.07.2021 13:07, Vladimir Davydov via Tarantool-patches wrote: > This patch moves method_decoder table from Lua to C. This is a step > towards rewriting performance-critical parts of net.box in C. > --- > src/box/lua/net_box.c | 235 +++++++++++++++++++++++++++++++--------- > src/box/lua/net_box.lua | 43 +------- > 2 files changed, 189 insertions(+), 89 deletions(-) > > diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c > index 49030aabea69..c0c3725e5350 100644 > --- a/src/box/lua/net_box.c > +++ b/src/box/lua/net_box.c > @@ -678,6 +678,79 @@ netbox_encode_method(struct lua_State *L) <...> > + > +/** > + * Decode Tarantool response body consisting of single > + * IPROTO_DATA key into Lua table. > + * @param L Lua stack to push result on. > + * @param data MessagePack. > + * @retval Lua table 1. It is not necessary to write these doxygen comments for each param really if you think they are obvious. The only 'rule' is to comment the function on its first declaration. Up to you of course. Not a rule. > + */ > +static void > +netbox_decode_table(struct lua_State *L, const char **data, > + const char *data_end, struct tuple_format *format) > +{ > + (void) data_end; > + (void) format; > + netbox_skip_to_data(data); > + luamp_decode(L, cfg, data); > +} > + > +/** > + * Same as netbox_decode_table, but only decodes the first element of the > + * table, skipping the rest. Used to decode index.count() call result. > + * @param L Lua stack to push result on. > + * @param data MessagePack. > + * @retval count or nil. > + */ > +static void > +netbox_decode_value(struct lua_State *L, const char **data, > + const char *data_end, struct tuple_format *format) > +{ > + (void) data_end; > + (void) format; > + netbox_skip_to_data(data); > + uint32_t count = mp_decode_array(data); > + for (uint32_t i = 0; i < count; ++i) { > + if (i == 0) > + luamp_decode(L, cfg, data); > + else > + mp_next(data); 2. Is the compiler able to turn this into?: ... if (count == 0) return lua_pushnil(L); luamp_decode(L, cfg, data); for (uint32_t i = 1; i < count; ++i) mp_next(data); } And why not do it right away? It looks shorter and a bit simpler IMO. Up to you. > + } > + if (count == 0) > + lua_pushnil(L); > +} > + > /** > * Decode IPROTO_DATA into tuples array. > * @param L Lua stack to push result on. > @@ -704,31 +777,45 @@ netbox_decode_data(struct lua_State *L, const char **data, <...> > + > +/** > + * Same as netbox_decode_select, but only decodes the first tuple of the array, > + * skipping the rest. > + * @param L Lua stack to push result on. > + * @param data MessagePack. > + * @retval Tuple or nil. > + */ > +static void > +netbox_decode_tuple(struct lua_State *L, const char **data, > + const char *data_end, struct tuple_format *format) > +{ > + (void) data_end; > + netbox_skip_to_data(data); > + uint32_t count = mp_decode_array(data); > + for (uint32_t i = 0; i < count; ++i) { > + const char *begin = *data; > + mp_next(data); > + if (i > 0) > + continue; > + struct tuple *tuple = box_tuple_new(format, begin, *data); > + if (tuple == NULL) > + luaT_error(L); > + luaT_pushtuple(L, tuple); > + } > + if (count == 0) > + lua_pushnil(L); 3. Ditto. Wouldn't it be shorter and a bit easier to read by doing this?: ... if (count == 0) return lua_pushnil(L); struct tuple *tuple = box_tuple_new(format, begin, *data); if (tuple == NULL) luaT_error(L); luaT_pushtuple(L, tuple); for (uint32_t i = 1; i < count; ++i) mp_next(data); } Up to you.