Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Aug 2010 15:38:54 +0200
From:      =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
To:        Gabor Kovesdan <gabor@FreeBSD.org>
Cc:        delphij@FreeBSD.org, Dimitry Andric <dimitry@andric.com>, Doug Barton <dougb@FreeBSD.org>, core@FreeBSD.org, current@FreeBSD.org
Subject:   Re: Official request: Please make GNU grep the default
Message-ID:  <86aaoirac1.fsf@ds4.des.no>
References:  <4C6505A4.9060203@FreeBSD.org> <4C6C1CFE.6060900@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Gabor Kovesdan <gabor@FreeBSD.org> 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.

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:

% time sh -c 'for n in $(jot 1000) ; do /usr/obj/usr/src/usr.bin/grep/grep =
-q "^xfce4-wm" /usr/ports/INDEX-9 ; done'=20
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/g=
rep -q "^xfce4-wm" /usr/ports/INDEX-9 ; done'
sh -c   7.98s user 7.47s system 100% cpu 15.424 total

The bottleneck is now in quite an unexpected location:

  %   cumulative   self              self     total=20=20=20=20=20=20=20=20=
=20=20=20
 time   seconds   seconds    calls  ms/call  ms/call  name=20=20=20=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_c=
ommon [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 [39]
  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_easy=
 [40]
  0.1       0.09     0.00       54     0.00     0.00  arena_avail_tree_inse=
rt [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_setrunelocale =
[21]
  0.1       0.09     0.00        0   21.76%           re_string_destruct [1=
4]
  0.1       0.09     0.00        0  100.00%           regexec [38]

The culprit seems to be the first memchr() in grep_fgetln().  For some
reason, even with -O2, it is not inlined:

% echo "disassemble grep_fgetln" | gdb -q -batch -x /dev/stdin /usr/obj/usr=
/src/usr.bin/grep/grep | grep memchr
0x000000000040291e <grep_fgetln+244>:	callq  0x40176c <memchr>
0x00000000004029fa <grep_fgetln+464>:	callq  0x40176c <memchr>

DES
--=20
Dag-Erling Sm=C3=B8rgrav - des@des.no



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86aaoirac1.fsf>