Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH 1/5] qsync: eliminate redundant writes
Date: Sat, 11 Jul 2020 00:04:39 +0300	[thread overview]
Message-ID: <20200710210439.GG1999@grain> (raw)
In-Reply-To: <bbbafe41-1773-2b80-6ac7-1661711cde9b@tarantool.org>

On Fri, Jul 10, 2020 at 10:31:22PM +0200, Vladislav Shpilevoy wrote:
> Hi!
> 
> On 10/07/2020 09:56, Cyrill Gorcunov wrote:
> > Instead of updating is_sync variable on every
> > cycle write it once.
> > 
> > Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> > ---
> >  src/box/txn.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/src/box/txn.c b/src/box/txn.c
> > index a2df23833..49b2b2649 100644
> > --- a/src/box/txn.c
> > +++ b/src/box/txn.c
> > @@ -567,8 +567,12 @@ txn_journal_entry_new(struct txn *txn)
> >  		if (stmt->row == NULL)
> >  			continue;
> >  
> > -		is_sync = is_sync || (stmt->space != NULL &&
> > -				      stmt->space->def->opts.is_sync);
> > +		if (!is_sync) {
> > +			if (stmt->space != NULL &&
> > +			    stmt->space->def->opts.is_sync) {
> > +				is_sync = true;
> > +			}
> > +		}
> >  
> >  		if (stmt->row->replica_id == 0)
> >  			*local_row++ = stmt->row;
> 
> The 'redundant' writes were done intentionally, to avoid unnecessary
> branching. I see no point in this change.

Vlad, I'm sorry to say that your assumption about unnecessary branching
is simply wrong. Look, the || operator means that there is a read and
compare on asm level, iow there is _already_ a branch present while it
might be not that obvious on C level.

0000000000002578 <txn_journal_entry_new>:
...
    26ab:       84 c0                   test   %al,%al
    26ad:       74 07                   je     26b6 <txn_journal_entry_new+0x13e>
    26af:       b8 01 00 00 00          mov    $0x1,%eax
    26b4:       eb 05                   jmp    26bb <txn_journal_entry_new+0x143>
    26b6:       b8 00 00 00 00          mov    $0x0,%eax
    26bb:       88 45 e7                mov    %al,-0x19(%rbp)
    26be:       80 65 e7 01             andb   $0x1,-0x19(%rbp)

see this test+je pair? IOW, in my version we eliminate redundant write operation.
And just for the future -- branching is cheaper than write operation on hot paths.

  reply	other threads:[~2020-07-10 21:04 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-10  7:56 [Tarantool-patches] [PATCH 0/5] qsync: code cleanup Cyrill Gorcunov
2020-07-10  7:56 ` [Tarantool-patches] [PATCH 1/5] qsync: eliminate redundant writes Cyrill Gorcunov
2020-07-10 20:31   ` Vladislav Shpilevoy
2020-07-10 21:04     ` Cyrill Gorcunov [this message]
2020-07-10  7:56 ` [Tarantool-patches] [PATCH 2/5] qsync: add a comment about sync txn in journal allocation Cyrill Gorcunov
2020-07-10 20:33   ` Vladislav Shpilevoy
2020-07-10 20:34     ` Vladislav Shpilevoy
2020-07-10 21:07       ` Cyrill Gorcunov
2020-07-10 21:08         ` Vladislav Shpilevoy
2020-07-11 16:08   ` Vladislav Shpilevoy
2020-07-10  7:56 ` [Tarantool-patches] [PATCH 3/5] qsync: txn_commit_async -- drop redundant variable Cyrill Gorcunov
2020-07-10 20:35   ` Vladislav Shpilevoy
2020-07-10 21:10     ` Cyrill Gorcunov
2020-07-10 21:28       ` Vladislav Shpilevoy
2020-07-10 21:36         ` Cyrill Gorcunov
2020-07-11 14:10           ` Vladislav Shpilevoy
2020-07-11 15:18             ` Cyrill Gorcunov
2020-07-10  7:56 ` [Tarantool-patches] [PATCH 4/5] qsync: txn_commit -- use txn flag instead of caching variable Cyrill Gorcunov
2020-07-10 20:36   ` Vladislav Shpilevoy
2020-07-10 21:27     ` Cyrill Gorcunov
2020-07-10  7:56 ` [Tarantool-patches] [PATCH 5/5] qsync: sanitize txn_limbo_on_rollback Cyrill Gorcunov
2020-07-10 20:38   ` Vladislav Shpilevoy
2020-07-11 15:46     ` Cyrill Gorcunov

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=20200710210439.GG1999@grain \
    --to=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/5] qsync: eliminate redundant writes' \
    /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