patchgrep - Patches: patch #6288, 30% speedup by changing one...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #6288: 30% speedup by changing one MALLOC() to a CALLOC()

Submitter:  Johan Walles <walles>
Submitted:  Tue 27 Nov 2007 04:04:51 PM UTC
   
 
Category:  None Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  None Open/Closed:  Closed

Sat 09 Feb 2008 08:07:05 PM UTC, comment #2: 

Committed. Thanks!

Tony Abou-Assaleh <taa>
Group administrator
Sat 05 Jan 2008 08:55:19 AM UTC, comment #1: 

This is what the change looks like as described by diff.  It still wins 30% performance in a use-case I have once every hour of the day.

diff -ur grep-2.5.3/src/dfa.c grep-2.5.3-johan/src/dfa.c
--- grep-2.5.3/src/dfa.c        2007-06-28 20:57:19.000000000 +0200
+++ grep-2.5.3-johan/src/dfa.c  2008-01-05 09:46:54.000000000 +0100
@@ -1605,9 +1605,7 @@
   int *visited;
   position p, old;
 
-  MALLOC(visited, int, d->tindex);
-  for (i = 0; i < d->tindex; ++i)
-    visited[i] = 0;
+  CALLOC(visited, int, d->tindex);
 
   for (i = 0; i < s->nelem; ++i)
     if (d->tokens[s->elems[i].index] >= NOTCHAR

Johan Walles <walles>
Tue 27 Nov 2007 04:04:51 PM UTC, original submission:  

http://bugs.debian.org/450649

egrep becomes 30% faster in a real world use-case if you replace one malloc() + for() loop with a calloc().  Top of epsclosure(), dfa.c.

The real-world use case is running logcheck on my home system.


Details:
I've been profiling egrep since it uses lots of CPU when logcheck does its thing.

In dfa.c, top of function epsclosure, we have this (with oprofile sample counts):

               :  MALLOC(visited, int, d->tindex);
 48796 16.2440 :  for (i = 0; i < d->tindex; ++i)
 94442 31.4394 :    visited[i] = 0;

Replacing the home-made memset() loop above with doing CALLOC instead we get:

               :  CALLOC(visited, int, d->tindex);
               :  // for (i = 0; i < d->tindex; ++i)
               :  //   visited[i] = 0;

Zero samples.  But obviously all that didn't just disappear.  It went into memset:

samples  %        image name               app name                 symbol name
60474    22.3932  libc-2.6.1.so            libc-2.6.1.so            memset

So instead of taking 50% of the CPU time with MALLOC(), it takes 22% with CALLOC().

Please change MALLOC() to CALLOC() and remove the loop.

  Regards Johan

Johan Walles <walles>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #14751:  alotfaster.patch added by walles (459B - text/x-diff - The four line patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by taa (Posted a comment)
  • -email is unavailable- added by walles (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2008-02-09 taa StatusNone Done
        Open/ClosedOpen Closed
    2008-01-05 walles Attached File- Added alotfaster.patch, #14751

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code