I did some profiling of Xith3d and decided to list some parts of Xith methods and classes that create most work for the garbage collector. I do not know if any of these object creations can be avoided, e.g. by reusing existing objects but I decided to list the methods anyway as I got the report easily while evaluating the profiler.
My test application consisted of 200 objects that are constantly rotated and positioned. The instance count list below consists of Xith objects only. The counts are a result from 2000 view.renderOnce() calls only, so you can double the counts below after each 2000 more frames etc. GC was disabled.
And here is the top instance list:
5719196 double[]
1623184 Object[]
273137 java.util.ArrayList
271142 long[]
271137 com.xith3d.render.StateSortableMap
271137 com.xith3d.render.ColoringShader
271137 com.xith3d.render.ShapeAtom
271137 com.xith3d.render.TextureShader
271137 com.xith3d.render.TransformShader
70943 com.xith3d.render.MaterialShader
64944 float[]
15992 javax.vecmath.Vector3f
8000 com.xith3d.render.RenderingShader
8000 com.xith3d.render.PolygonAttrShader
…
The most interesting part is hefty amount of doubles, 6 million after 2000 frame iterations.
Have no clue what creates these doubles but if I add following code to Xith instead, then renderOnce() (actually getScale method) does no longer create doubles excessively .
com.xith3d.scenegraph.Transform3D
public float getScale() {
//return matrix.getScale(); OLD LINE
return matrix.getScaleCustom(); // new line
}
com.xith3d.datatypes.MatrixExt4f
// new method
public final float getScaleCustom() {
return (float) Math.sqrt((m00 * m00 + m10 * m10 + m20 * m20 + m01
* m01 + m11 * m11 + m21 * m21 + m02 * m02 + m12 * m12 + m22
* m22) / 3.0);
}
And here are the “hotspots” of object creations…
com.xith3d.render.TransformShader
makeTransformShader()
-new TransformShader
com.xith3d.render.RenderAtomBase
-new StateSortableMap
-new ArrayList
com.xith3d.render.StateSortableMap
-new StateSortable array
-new long array
com.xith3d.render.ColoringShader
makeColoringShader()
-new ColoringShader
com.xith3d.render.TextureShader
makeTextureShader
-new TextureShader
com.xith3d.scenegraph.View
getAtom
-new ShapeAtom
com.xith3d.scenegraph.Node
updateBounds
-new Bounds array
Hope this info was any good, Jani!