Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun <skaplun@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] lua: lua_field_inspect_table without pushcfunction
Date: Tue, 19 May 2020 13:29:24 +0300	[thread overview]
Message-ID: <20200519102924.GA27691@root> (raw)
In-Reply-To: <74b93f1b-5515-6f8a-32d6-4672e312eb51@tarantool.org>

Hi! Thanks for the review!

On 18.05.20, Vladislav Shpilevoy wrote:
> On 18/05/2020 11:37, Sergey Kaplun wrote:
> > Currently on encoding table we push cfunction (lua_field_try_serialize)
> > to lua stack with additional lightuserdata and table value and after
> > pcall that function to avoid a raise of error.
> > 
> > In this case LuaJIT creates new object which will not live long time,
> > so it increase amount of dead object and also increase time and
> > frequency of garbage collection inside LuaJIT.
> > Also this pcall is necessary only in case when metafield __serialize
> > of serilizable object has LUA_TFUNCTION type.
> > 
> > So instead pushcfunction with pcall we can directly call the function
> > trying to serialize an object.
> > ---
> 
> 1. Is there a measurement, how much does this patch help and when,
> exactly?

I was faced this when I was looking at the flamegraphs by Aleksandr
Lyapunov related to https://github.com/tarantool/vshard/issues/224
At vshard_router.svg you can see that mp_encode_lua call-chain comes to
luamp_inspect_table, with pushcfunction and gc_step respectively.

So I suppose that simple test with mp_lua_encode would be enough (see
example below) to see a difference.
Note: for your local machine 1e5-1e6 itterations would be ok.

| 20:15:42 jobs:0 s.kaplun@dev4:~/tarantool_builds/lua_mp_pcall$
| >>> src/tarantool
| Tarantool 2.5.0-32-g7f20272
| type 'help' for interactive help
| tarantool> c1_source = {
|                setmetatable({[180] = 10, [1] = 0}, {__serialize = "map"}),
|                setmetatable({
|                    [34] = "vshard.router.call_rw",
|                    [33] = {148, 0, "bench_call_select_r"}
|                }, {__serialize = "map"})
|            }
| ---
| ...
| 
| tarantool> local msgpack = require"msgpack"
|            local clock = require"clock"
|            local S = clock.proc()
|            for i=1,1e7 do msgpack.encode(c1_source) end
|            return clock.proc() - S
| ---
| - 9.968856686
| ...
| 
| tarantool> 21:00:32 jobs:0 s.kaplun@dev4:~/tarantool_builds/lua_mp_pcall$
| >>> ../master/src/tarantool
| Tarantool 2.5.0-32-g7f20272
| type 'help' for interactive help
| tarantool> c1_source = {
|                setmetatable({[180] = 10, [1] = 0}, {__serialize = "map"}),
|                setmetatable({
|                    [34] = "vshard.router.call_rw",
|                    [33] = {148, 0, "bench_call_select_r"}
|                }, {__serialize = "map"})
|            }
| ---
| ...
| 
| tarantool> local msgpack = require"msgpack"
|            local clock = require"clock"
|            local S = clock.proc()
|            for i=1,1e7 do msgpack.encode(c1_source) end
|            return clock.proc() - S
| ---
| - 12.622932064

-- 
Best regards,
Sergey Kaplun

  reply	other threads:[~2020-05-19 10:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18  9:37 Sergey Kaplun
2020-05-18 21:52 ` Vladislav Shpilevoy
2020-05-19 10:29   ` Sergey Kaplun [this message]
2020-05-19 20:08     ` Vladislav Shpilevoy
2020-05-22 11:48 ` Aleksandr Lyapunov
2020-05-22 14:05 ` Alexander Turenko
2020-05-25 12:06   ` Sergey Kaplun
2020-06-02  0:19 ` Igor Munkin
2020-06-02  9:36   ` Igor Munkin
2020-06-10 12:15 ` Kirill Yukhin
2020-06-10 13:01   ` Igor Munkin
2020-06-10 13:39     ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200519102924.GA27691@root \
    --to=skaplun@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] lua: lua_field_inspect_table without pushcfunction' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox