From owner-freebsd-current@FreeBSD.ORG Thu Aug 19 15:34:29 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2D6FC10656C8 for ; Thu, 19 Aug 2010 15:34:29 +0000 (UTC) (envelope-from tijl@coosemans.org) Received: from mailrelay012.isp.belgacom.be (mailrelay012.isp.belgacom.be [195.238.6.179]) by mx1.freebsd.org (Postfix) with ESMTP id B78188FC1B for ; Thu, 19 Aug 2010 15:34:28 +0000 (UTC) X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao4FAGzqbExbsdUI/2dsb2JhbACTOY0acr4OhTcE Received: from 8.213-177-91.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([91.177.213.8]) by relay.skynet.be with ESMTP; 19 Aug 2010 17:34:26 +0200 Received: from kalimero.tijl.coosemans.org (kalimero.tijl.coosemans.org [127.0.0.1]) by kalimero.tijl.coosemans.org (8.14.4/8.14.4) with ESMTP id o7JFYPDO005211; Thu, 19 Aug 2010 17:34:26 +0200 (CEST) (envelope-from tijl@coosemans.org) From: Tijl Coosemans To: freebsd-current@freebsd.org Date: Thu, 19 Aug 2010 17:34:15 +0200 User-Agent: KMail/1.13.5 (FreeBSD/8.1-PRERELEASE; KDE/4.4.5; i386; ; ) References: <4C6505A4.9060203@FreeBSD.org> <4C6C1CFE.6060900@FreeBSD.org> <86aaoirac1.fsf@ds4.des.no> In-Reply-To: <86aaoirac1.fsf@ds4.des.no> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart2110530.gFL3sNdave"; protocol="application/pgp-signature"; micalg=pgp-sha256 Content-Transfer-Encoding: 7bit Message-Id: <201008191734.25162.tijl@coosemans.org> Cc: Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?= , Dimitry Andric , Gabor Kovesdan Subject: Re: Official request: Please make GNU grep the default X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Aug 2010 15:34:29 -0000 --nextPart2110530.gFL3sNdave Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable On Thursday 19 August 2010 15:38:54 Dag-Erling Sm=F8rgrav wrote: > Gabor Kovesdan writes: >> I've just committed a patch with the kind help of Dimitry Andric, >> which gives BSD grep a huge performance boost. The performance is >> now almost comparable to GNU grep. >=20 > Not quite, as Doug pointed out. I don't know what benchmark you're > using, but I'm using a greatly simplified variant of Doug's: >=20 > % time sh -c 'for n in $(jot 1000) ; do /usr/obj/usr/src/usr.bin/grep/gre= p -q "^xfce4-wm" /usr/ports/INDEX-9 ; done' > sh -c 13.57s user 7.06s system 99% cpu 20.783 total > % time sh -c 'for n in $(jot 1000) ; do /usr/obj/usr/src/gnu/usr.bin/grep= /grep -q "^xfce4-wm" /usr/ports/INDEX-9 ; done' > sh -c 7.98s user 7.47s system 100% cpu 15.424 total >=20 > The bottleneck is now in quite an unexpected location: >=20 > % cumulative self self total =20 > time seconds seconds calls ms/call ms/call name =20 > 38.8 0.03 0.03 12717 0.00 0.00 memchr [5] > 35.6 0.07 0.03 395 0.08 0.08 _read [6] > 16.4 0.08 0.01 0 100.00% _mcount [7] > 1.7 0.08 0.00 12362 0.00 0.00 memset [9] > 1.5 0.08 0.00 0 100.00% .mcount (110) > 1.5 0.08 0.00 0 43.41% re_search_internal = [8] > 0.8 0.08 0.00 820 0.00 0.00 memcpy [12] > 0.6 0.09 0.00 37045 0.00 0.00 free [13] > 0.6 0.09 0.00 12332 0.00 0.01 grep_fgetln [4] > 0.6 0.09 0.00 1 0.49 66.27 procfile [3] > 0.4 0.09 0.00 0 100.00% re_string_construct= _common [26] > 0.3 0.09 0.00 1 0.25 0.34 _Read_RuneMagi [27] > 0.1 0.09 0.00 261 0.00 0.00 arena_avail_comp [3= 9] > 0.1 0.09 0.00 155 0.00 0.00 arena_malloc [24] > 0.1 0.09 0.00 153 0.00 0.00 arena_bin_malloc_ea= sy [40] > 0.1 0.09 0.00 54 0.00 0.00 arena_avail_tree_in= sert [35] > 0.1 0.09 0.00 5 0.02 0.02 arena_purge [37] > 0.1 0.09 0.00 3 0.04 0.44 setlocale [10] > 0.1 0.09 0.00 1 0.12 0.46 __wrap_setrunelocal= e [21] > 0.1 0.09 0.00 0 21.76% re_string_destruct = [14] > 0.1 0.09 0.00 0 100.00% regexec [38] >=20 > The culprit seems to be the first memchr() in grep_fgetln(). For some > reason, even with -O2, it is not inlined: >=20 > % echo "disassemble grep_fgetln" | gdb -q -batch -x /dev/stdin /usr/obj/u= sr/src/usr.bin/grep/grep | grep memchr > 0x000000000040291e : callq 0x40176c > 0x00000000004029fa : callq 0x40176c The base system gcc doesn't have a built-in version of memchr to inline. --nextPart2110530.gFL3sNdave Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (FreeBSD) iF4EABEIAAYFAkxtTwAACgkQfoCS2CCgtisAkwD9H+rFVCNMWWLeII5ypHPhhQ3D AxdYjKL5+cUOj5CdlNIA/3f7VpB3j7s+vDkfXEKeAWvlX6/nwe3E7tmNLquc5wLj =p7mQ -----END PGP SIGNATURE----- --nextPart2110530.gFL3sNdave--