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 1DE9C6EC58; Thu, 24 Jun 2021 23:00:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1DE9C6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1624564832; bh=4CAXNDNvAi5W5fBGxYjQRbyPnDKiXgj9GREwhKpaQ/w=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=j5nDlhy1/2E33CpJYeX3h974vVamTSNpvog808wasEKP3k09YMxCxLb4dTNId0Rze bTLujRaCr8UQwKK+AviAU/NrPKYKXJSrD5iJF0MV0mjbfOny2QuEE2fJhkYEuyOieD lE0ho46YV+HaAIhyESiaPqe0WBPoVMVO07avGUY8= Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 C0F2B6EC58 for ; Thu, 24 Jun 2021 23:00:30 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C0F2B6EC58 Received: by smtp63.i.mail.ru with esmtpa (envelope-from ) id 1lwVWX-0002vv-Nh; Thu, 24 Jun 2021 23:00:30 +0300 To: Sergey Kaplun References: <20210618181416.25454-1-skaplun@tarantool.org> <67687e87-fb0e-1477-ac76-5fa9b04b9e3a@tarantool.org> Message-ID: Date: Thu, 24 Jun 2021 22:00:28 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD954DFF1DC42D673FB8EEAA58EF109ED2DCA3B880632F394B8182A05F538085040727F362B7C3D0671113A8AFED0255771DEC88AEADBDBA6166C3BCC28E311DEAA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70C5E0F71D77D667BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637835928C62272F24E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8CC46D91828B48495D7C58F639EBA02F1117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B974A882099E279BDA471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FCED03C93EBFE568B33AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F7900637E643E67EAB77E948D81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16BA91E23F1B6B78B78B5C8C57E37DE458BEDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4ADBA7B03D8541B7678AFC22D38166BCE30 X-C1DE0DAB: 0D63561A33F958A5484E825D49D4FEDB340A60BB0439EF0F4ECEECCBD97C32DCD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75F04B387B5D7535DE410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D7D5115130EFC82464253E6A8C41E1F91AB4158D9ABC60056E527700175B7155EC7A6F052CF333D71D7E09C32AA3244C90CEED1D6E16F87ED4644A49FC985523C86C126E7119A0FEFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojYpdkWC5QM10qrH/O2ezFVA== X-Mailru-Sender: 504CC1E875BF3E7D9BC0E5172ADA3110FE28A59B6F1D66177EFE0AFAFD882A0557641CE2A9D4433007784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6112434F685709FCF0DA7A0AF5A3A8387 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the investigation! >>> 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). That looks suspicious. Why does it have such a small impact? Did you check that multireturn really made the stack bigger? Shouldn't it have linear complexity depending on the stack size after the target index? The patch looks fine to me, if the benchmarks show there is even a slight perf win. But I think Igor should take another look.