From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E7EC7445320 for ; Sat, 11 Jul 2020 00:04:42 +0300 (MSK) Received: by mail-lj1-f196.google.com with SMTP id b25so7945412ljp.6 for ; Fri, 10 Jul 2020 14:04:42 -0700 (PDT) Date: Sat, 11 Jul 2020 00:04:39 +0300 From: Cyrill Gorcunov Message-ID: <20200710210439.GG1999@grain> References: <20200710075605.217824-1-gorcunov@gmail.com> <20200710075605.217824-2-gorcunov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Tarantool-patches] [PATCH 1/5] qsync: eliminate redundant writes List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tml 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 > > --- > > 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 : ... 26ab: 84 c0 test %al,%al 26ad: 74 07 je 26b6 26af: b8 01 00 00 00 mov $0x1,%eax 26b4: eb 05 jmp 26bb 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.