From bbd6c613f0d831c059a9808ada5b4365ee1b6d20 Mon Sep 17 00:00:00 2001 From: shadowislord Date: Sat, 8 Nov 2014 18:04:03 -0500 Subject: [PATCH] Reduce "Integer" class churn in rendering statistics * Use IntMap instead of HashMap * Cache last set shader to save hashmap lookup on every set uniform --- .../java/com/jme3/renderer/Statistics.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/Statistics.java b/jme3-core/src/main/java/com/jme3/renderer/Statistics.java index 47f5da2fe..9d44e6566 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/Statistics.java +++ b/jme3-core/src/main/java/com/jme3/renderer/Statistics.java @@ -35,6 +35,7 @@ import com.jme3.scene.Mesh; import com.jme3.shader.Shader; import com.jme3.texture.FrameBuffer; import com.jme3.texture.Image; +import com.jme3.util.IntMap; import java.util.HashSet; /** @@ -60,10 +61,12 @@ public class Statistics { protected int memoryFrameBuffers; protected int memoryTextures; - protected HashSet shadersUsed = new HashSet(); - protected HashSet texturesUsed = new HashSet(); - protected HashSet fbosUsed = new HashSet(); + protected IntMap shadersUsed = new IntMap(); + protected IntMap texturesUsed = new IntMap(); + protected IntMap fbosUsed = new IntMap(); + protected int lastShader = -1; + /** * Returns a list of labels corresponding to each statistic. * @@ -148,9 +151,15 @@ public class Statistics { if( !enabled ) return; - - if (!shadersUsed.contains(shader.getId())) - shadersUsed.add(shader.getId()); + + // Reduces unneccessary hashmap lookups if + // we already considered this shader. + if (lastShader != shader.getId()) { + lastShader = shader.getId(); + if (!shadersUsed.containsKey(shader.getId())) { + shadersUsed.put(shader.getId(), null); + } + } if (wasSwitched) numShaderSwitches++; @@ -177,8 +186,8 @@ public class Statistics { if( !enabled ) return; - if (!texturesUsed.contains(image.getId())) - texturesUsed.add(image.getId()); + if (!texturesUsed.containsKey(image.getId())) + texturesUsed.put(image.getId(), null); if (wasSwitched) numTextureBinds ++; @@ -197,8 +206,8 @@ public class Statistics { if (fb != null){ assert fb.getId() >= 1; - if (!fbosUsed.contains(fb.getId())) - fbosUsed.add(fb.getId()); + if (!fbosUsed.containsKey(fb.getId())) + fbosUsed.put(fb.getId(), null); } if (wasSwitched) @@ -220,6 +229,8 @@ public class Statistics { numTextureBinds = 0; numFboSwitches = 0; numUniformsSet = 0; + + lastShader = -1; } /**