svn commit: r211463 - head/usr.bin/grep

Gabor Kovesdan gabor at
Wed Aug 18 21:02:38 UTC 2010

  Em 2010.08.18. 22:48, mdf at escreveu:
> On Wed, Aug 18, 2010 at 10:40 AM, Gabor Kovesdan<gabor at>  wrote:
>> Author: gabor
>> Date: Wed Aug 18 17:40:10 2010
>> New Revision: 211463
>> URL:
>> Log:
>>   - Refactor file reading code to use pure syscalls and an internal buffer
>>     instead of stdio.  This gives BSD grep a very big performance boost,
>>     its speed is now almost comparable to GNU grep.
> I didn't read all of the details in the profiling mails in the thread,
> but does this mean that work on stdio would give a performance boost
> to many apps?  Or is there something specific about how grep(1) is
> using its input that makes it a horse of a different color?
In stdio, there is some overhead of FILE * locking but in first phase we 
reduced that overhead by locking once after opening and releasing the 
lock once before closing (it's fine given that grep isn't threaded). In 
the previous code, grep read data by character (calling fgetc_unlocked) 
and now it reads in bigger chunks, this is another difference, which may 
have improved the performance. We haven't checked using stdio in chunks, 
because dealing directly with file descriptors made it easier to handle 
gzip/bzip2 files, so after having seen that the old solution was wrong, 
this idea came directly. So I cannot surely answer the question. It 
would be an interesting task to run a benchmark on this, though.


More information about the svn-src-all mailing list