From 5dab9cfab25bdcc50212b9697491a5239885b7d3 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 23 Mar 2011 04:49:18 +0000 Subject: [PATCH] ArrayList.contains shows up as a hot spot in pathfinding. Let's try using an identity hash set to accelerate it (identity hash set uses linear probing, which can give better cache performance than the chaining used by the normal hash set). git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1129 ed5b42cb-e716-0410-a449-f6a68f950b19 --- pom.xml | 2 +- src/main/java/com/threerings/media/util/AStarPathUtil.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index eb98213b..0dcbd9fc 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ com.google.guava guava - r07 + r08 compile diff --git a/src/main/java/com/threerings/media/util/AStarPathUtil.java b/src/main/java/com/threerings/media/util/AStarPathUtil.java index faf18030..f166f4e9 100644 --- a/src/main/java/com/threerings/media/util/AStarPathUtil.java +++ b/src/main/java/com/threerings/media/util/AStarPathUtil.java @@ -23,12 +23,14 @@ package com.threerings.media.util; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.awt.Point; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import com.samskivert.util.HashIntMap; @@ -324,7 +326,7 @@ public class AStarPathUtil public SortedSet open; /** The set of closed nodes being searched. */ - public ArrayList closed; + public Set closed; /** The destination coordinates in the tile array. */ public int destx, desty; @@ -344,7 +346,7 @@ public class AStarPathUtil // construct the open and closed lists open = new TreeSet(); - closed = Lists.newArrayList(); + closed = Sets.newIdentityHashSet(); } /**