Got a license from Intel for vtune. The first performance analysis showed an unexpected bottleneck:

apparently the UnionFind / island management had unexpected overhead. Added path compression to the UnionFind::find operation, and iterative over the actual islands, rather then over all number of objects.
This commit is contained in:
ejcoumans
2006-08-29 23:37:32 +00:00
parent 4cdcee8871
commit e1b85d1969
3 changed files with 91 additions and 64 deletions

View File

@@ -24,6 +24,12 @@ int UnionFind::find(int x)
while (x != m_id[x])
{
//not really a reason not to use path compression, and it flattens the trees/improves find performance dramatically
#define USE_PATH_COMPRESSION 1
#ifdef USE_PATH_COMPRESSION
//
m_id[x] = m_id[m_id[x]];
#endif //
x = m_id[x];
assert(x < m_N);
assert(x >= 0);
@@ -89,6 +95,8 @@ void UnionFind ::unite(int p, int q)
int i = find(p), j = find(q);
if (i == j)
return;
//weighted quick union, this keeps the 'trees' balanced, and keeps performance of unite O( log(n) )
if (m_sz[i] < m_sz[j])
{
m_id[i] = j; m_sz[j] += m_sz[i];