From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Nikita Pettik <korablev@tarantool.org>, Igor Munkin <imun@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH] tuple: make tuple_bless() compilable Date: Fri, 22 Oct 2021 16:02:25 +0300 [thread overview] Message-ID: <20211022130225.6076-1-skaplun@tarantool.org> (raw) tuple_bless() uses a tail call to ffi.gc() with return to the caller. This tail call replaces the current (tuple_bless) frame with the frame of the callee (ffi.gc). When JIT tries to compile return from `ffi.gc()` to the frame below it aborts the trace recording with the error "NYI: return to lower frame". This patch replaces the tail call with using additional local variable returned to the caller right after. --- Actually, this patch become possible thanks to Michael Filonenko and his benchmarks of TDG runs with jit.dump() enabled. After analysis of this dump we realize that tuple_bless is not compiled. This uncompiled chunk of code leads to the JIT cancer for all possible workflows that use tuple_bless() (i.e. tuple:update() and tuple:upsert()). This change is really trivial, but adds almost x2 improvement of performance for tuple:update()/upsert() scenario. Hope, that this patch will be a stimulus for including benchmarks of our forward products like TDG to routine performance running with the corresponding profilers dumps. Benchmarks: Before patch: Update: | Tarantool 2.10.0-beta1-90-g31594b427 | type 'help' for interactive help | tarantool> local t = {} | for i = 1, 1e6 do | table.insert(t, box.tuple.new{'abc', 'def', 'ghi', 'abc'}) | end | local clock = require"clock" | local S = clock.proc() | for i = 1, 1e6 do t[i]:update{{"=", 3, "xxx"}} end | return clock.proc() - S; | --- | - 4.208298872 Upsert: 4.158661731 After patch: Update: | Tarantool 2.10.0-beta1-90-g31594b427 | type 'help' for interactive help | tarantool> local t = {} | for i = 1, 1e6 do | table.insert(t, box.tuple.new{'abc', 'def', 'ghi', 'abc'}) | end | local clock = require"clock" | local S = clock.proc() | for i = 1, 1e6 do t[i]:update{{"=", 3, "xxx"}} end | return clock.proc() - S; | --- | - 2.357670738 Upsert: 2.334134195 Branch: https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-tuple-bless-compile src/box/lua/tuple.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua index fa76f4f7f..73446ab22 100644 --- a/src/box/lua/tuple.lua +++ b/src/box/lua/tuple.lua @@ -98,7 +98,14 @@ local tuple_bless = function(tuple) -- overflow checked by tuple_bless() in C builtin.box_tuple_ref(tuple) -- must never fail: - return ffi.gc(ffi.cast(const_tuple_ref_t, tuple), tuple_gc) + -- XXX: If we use tail call (instead creating a new frame for + -- a call just replace the top one) here, then JIT tries + -- to compile return from `ffi.gc()` to the frame below. This + -- abort the trace recording with the error "NYI: return to + -- lower frame". So avoid tail call and use additional stack + -- slots (for the local variable and the frame). + local tuple_ref = ffi.gc(ffi.cast(const_tuple_ref_t, tuple), tuple_gc) + return tuple_ref end local tuple_check = function(tuple, usage) -- 2.31.0
next reply other threads:[~2021-10-22 13:04 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-22 13:02 Sergey Kaplun via Tarantool-patches [this message] 2021-10-27 11:06 ` Igor Munkin via Tarantool-patches 2021-10-27 13:16 ` Sergey Kaplun via Tarantool-patches 2021-11-08 12:35 ` Nikita Pettik via Tarantool-patches 2021-11-10 12:31 ` Igor Munkin via Tarantool-patches
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=20211022130225.6076-1-skaplun@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=imun@tarantool.org \ --cc=korablev@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH] tuple: make tuple_bless() compilable' \ /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