From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexey Dobriyan Subject: Re: [PATCH] dcache: faster dentry_cmp() Date: Wed, 15 Feb 2012 11:14:00 +0300 Message-ID: <20120215081400.GA3306@p183.telecom.by> References: <20120214224526.GA3478@p183.telecom.by> <20120214225839.GA23916@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel@vger.kernel.org, npiggin@kernel.dk To: Al Viro Return-path: Received: from mail-bk0-f46.google.com ([209.85.214.46]:53215 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754173Ab2BOIOH (ORCPT ); Wed, 15 Feb 2012 03:14:07 -0500 Received: by bkcjm19 with SMTP id jm19so678244bkc.19 for ; Wed, 15 Feb 2012 00:14:05 -0800 (PST) Content-Disposition: inline In-Reply-To: <20120214225839.GA23916@ZenIV.linux.org.uk> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Tue, Feb 14, 2012 at 10:58:39PM +0000, Al Viro wrote: > On Wed, Feb 15, 2012 at 01:45:27AM +0300, Alexey Dobriyan wrote: > > 1) consistently use "unsigned int" for dentry name length, > > 2) reuse subtraction result for return value, exact value doesn't matter > > because function is only used in boolean context, > > 3) use *p++ idiom for even better code. > > > > All of this results in performance speedup of "git diff" > > which is way out of statistical error (0.4% vs 0.15% of 3 sigma): > > > - if (scount != tcount) > > - return 1; > > + > > + ret = scount - tcount; > > + if (ret) > > + return ret; > > do { > > - ret = (*cs != *ct); > > + ret = *cs++ - *ct++; > > if (ret) > > break; > > - cs++; > > - ct++; > > tcount--; > > } while (tcount); > > return ret; > > I wonder what'll happen if you simply replace that loop with > return memcmp(cs, ct, tcount); > which is what it really is... It was memcmp() at some point and Nick changed it and it became faster. See 9d55c369bb5e695e629bc35cba2ef607755b3bee "fs: implement faster dentry memcmp".