Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 May 2014 03:05:53 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r266208 - head/usr.sbin/pmcstat
Message-ID:  <201405160305.s4G35ro0067510@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Fri May 16 03:05:53 2014
New Revision: 266208
URL: http://svnweb.freebsd.org/changeset/base/266208

Log:
  Speed up pmcstat by improving string hash
  
  In one case generating callgraph output from a 24MB system-wide sampling
  data file took 17.4 seconds on average.  Profiling showed pmcstat
  spending a lot of time in strcmp, due to hash collisions.
  
  Replacing the XOR-only hash with FNV-1a reduces the run time for my
  test by 40%.

Modified:
  head/usr.sbin/pmcstat/pmcstat_log.c

Modified: head/usr.sbin/pmcstat/pmcstat_log.c
==============================================================================
--- head/usr.sbin/pmcstat/pmcstat_log.c	Fri May 16 02:21:51 2014	(r266207)
+++ head/usr.sbin/pmcstat/pmcstat_log.c	Fri May 16 03:05:53 2014	(r266208)
@@ -307,10 +307,10 @@ pmcstat_stats_reset(int reset_global)
 static int
 pmcstat_string_compute_hash(const char *s)
 {
-	int hash;
+	unsigned hash;
 
-	for (hash = 0; *s; s++)
-		hash ^= *s;
+	for (hash = 2166136261; *s; s++)
+		hash = (hash ^ *s) * 16777619;
 
 	return (hash & PMCSTAT_HASH_MASK);
 }



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