Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Jun 2014 17:08:04 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r267415 - stable/9/usr.sbin/pmcstat
Message-ID:  <201406121708.s5CH84Ef049261@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Thu Jun 12 17:08:04 2014
New Revision: 267415
URL: http://svnweb.freebsd.org/changeset/base/267415

Log:
  MFC r266208: 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%.
  
  Approved by:	re

Modified:
  stable/9/usr.sbin/pmcstat/pmcstat_log.c
Directory Properties:
  stable/9/usr.sbin/pmcstat/   (props changed)

Modified: stable/9/usr.sbin/pmcstat/pmcstat_log.c
==============================================================================
--- stable/9/usr.sbin/pmcstat/pmcstat_log.c	Thu Jun 12 17:06:50 2014	(r267414)
+++ stable/9/usr.sbin/pmcstat/pmcstat_log.c	Thu Jun 12 17:08:04 2014	(r267415)
@@ -301,10 +301,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?201406121708.s5CH84Ef049261>