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 250276EC58; Tue, 22 Jun 2021 16:39:37 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 250276EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1624369177; bh=u0NPVSEAB/RrR0umcopy5UDvov0GxS6njMfOoi9u54c=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=zSn1sUKqkAmoIELHn3uESmTNtjtE5LAratWCzvWPuv00LTjtMYptNWM9XGqA0tvOG dbNoLYHay7NDE+79t/5R3v29S4d7iL/sDZclsTEQ3b5r9Hm68B78fv7F24XYJFRRg2 3yDKORswD2u+XW17qvLPimNISM8FeyD/SVld2uWA= Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [94.100.177.103]) (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 998756EC58 for ; Tue, 22 Jun 2021 16:39:35 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 998756EC58 Received: by smtp43.i.mail.ru with esmtpa (envelope-from ) id 1lvgco-0000EI-Er; Tue, 22 Jun 2021 16:39:35 +0300 Date: Tue, 22 Jun 2021 16:38:18 +0300 To: Vladislav Shpilevoy Message-ID: References: <20210618181416.25454-1-skaplun@tarantool.org> <67687e87-fb0e-1477-ac76-5fa9b04b9e3a@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <67687e87-fb0e-1477-ac76-5fa9b04b9e3a@tarantool.org> X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD91C2C07775F13263A65B2A0865841DD232D6C915D49D3808000894C459B0CD1B90C63D6AF20E782BB384C193D75CF6FD54F9D671607BAA148485234136DCFB6CD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D77100FFB2844417EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063719899BAB9B61B3948638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D855E2D2C275FEF59184F1DDE3890E7FBE117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6AC294AFEFA671E80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A594E0D3A7B8F86D62CF363FE79E9C9596DC5885AC4765E8ABD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75448CF9D3A7B2C848410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AAC3D1FDB34D048841E44FA081472026F87FC6AA0469B3C35A1A94FAF2539E00D06167DEA07FA9F21D7E09C32AA3244C4F84762147ECF245447728C1E4DAC91F3A76366E8A9DE7CAFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojrAWM8Mt/TOBvTKPFciMY/w== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB4F4603B94D2E222715924B777460705B3038946313079381BF2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A89437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH] lua: refactor port_lua_do_dump and encode_lua_call 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the review! On 21.06.21, Vladislav Shpilevoy wrote: > Hi! Thanks for the patch! > > > Branch: https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-refactor-lua-call > > See the benchmarks sources here [1]. > > > > Before patch: > > | Encode map: 189851357 mcs, 15.8 K ps > > | Encode seq: 187926351 mcs, 16.0 K ps > > | Encode str: 185451675 mcs, 16.2 K ps > > | Encode dig: 184833396 mcs, 16.2 K ps > > > > After patch: > > | Encode map: 187814261 mcs, 16.0 K ps > > | Encode seq: 183755028 mcs, 16.3 K ps > > | Encode str: 181571626 mcs, 16.5 K ps > > | Encode dig: 181572998 mcs, 16.5 K ps > > > > Looks like the perf doesn't degrade at least. > > > > [1]: https://gist.github.com/Buristan/3e6d6bf2c722874bec55a8c5a44b98f3 > > > > src/box/lua/call.c | 71 ++++++++++++++++++++++++++++++++++++---------- > > 1 file changed, 56 insertions(+), 15 deletions(-) > > > > diff --git a/src/box/lua/call.c b/src/box/lua/call.c > > index 0315e720c..3b2572096 100644 > > --- a/src/box/lua/call.c > > +++ b/src/box/lua/call.c > > @@ -450,13 +482,20 @@ port_lua_do_dump(struct port *base, struct mpstream *stream, > > struct encode_lua_ctx ctx; > > ctx.port = port; > > ctx.stream = stream; > > - struct lua_State *L = tarantool_L; > > - int top = lua_gettop(L); > > - if (lua_cpcall(L, handler, &ctx) != 0) { > > - luaT_toerror(port->L); > > + lua_State *L = port->L; > > + /* > > + * At the moment Lua stack holds only values to encode. > > + * Insert corresponding encoder to the bottom and push > > + * encode context as lightuserdata to the top. > > + */ > > + const int size = lua_gettop(L); > > + lua_rawgeti(L, LUA_REGISTRYINDEX, execute_lua_refs[handler]); > > + assert(lua_isfunction(L, -1) && lua_iscfunction(L, -1)); > > + lua_insert(L, 1); > > If I remember correctly, this leads to moving all the existing > stack elements forward. Which might be expensive. I know from > Vlad Grubov's words that they have code with hundreds of values in > multireturn from stored functions. Did you bench what happens when > the Lua coroutine contains a lot of values? In the bench by the > link above I see only 1-element array and map. Size of the array > and map does not matter though. Only multireturn is interesting > here. Like 'return 1, 2, 3, ...'. I've added this benchmark (200 numbers to return) to the gist. Local results for the bench: Master: | Encode mul: 237900953 mcs, 12.6 K ps My branch: | Encode mul: 235735350 mcs, 12.7 K ps `luamp_encode()` has the biggest impact in `port_do_lua_dump()` (`lua_insert()` costs ~0.1% of the whole runtime). -- Best regards, Sergey Kaplun