The Source for Java Technology Collaboration

Home » java.net Forums » Project Looking Glass 3D » Wonderland & MPK20 Interest

Thread: Long loading time using big X3D files - solved

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 1 - Last Post: Aug 25, 2008 1:29 PM by: paulby
jsalonen

Posts: 7
Long loading time using big X3D files - solved
Posted: Aug 25, 2008 4:30 AM
  Click to reply to this thread Reply

I have a big (10MB) X3D model file and it used to take over 20 minutes to load it into wonderland or j3dfly. I ran a profiler on the loading process to find out why it takes so long and traced the problem to the class com.sun.j3d.utils.geometry.GeometryInfo from the java3d-core-utils library.

It turned out that most of the time (over 90%) it takes to load a big X3D model is being spent in the method "getListIndices" which uses a HashMap to store instances of the private inner class GeometryInfo$IndexRow. Over 60% of the time was spent in hundreds of millions of calls to the equals method of IndexRow which meant that many instances of the class must have the same hash code. So I had a look at the hashCode method of that class and indeed, it returns 0 always!

When I replaced the original hashCode implementation with one of my own the loading time for the X3D model file went down from over 20 minutes to less than 2 minutes, most of which is spent in the xml library.

Here is the implementation of com.sun.j3d.utils.geometry.GeometryInfo$IndexRow.hashCode() that I used:
    public int hashCode()
    {
      int bits = 7;
      for (int i = 0 ; i < size ; i++) {
        bits = (31*bits) ^ val[i];
      }
      return bits;
    } // End of IndexRow.hashCode


Edit: I have also reported this in the Java3d issue tracker, https://java3d.dev.java.net/issues/show_bug.cgi?id=595

paulby

Posts: 2,068
Re: Long loading time using big X3D files - solved
Posted: Aug 25, 2008 1:29 PM   in response to: jsalonen
  Click to reply to this thread Reply

Good catch, thanks for the tracking down the fix. We've ported much of the GeometryInfo system to JME for 0.5, so I'll make sure this get applied to that code base as well.

Rgds

Paul




 XML java.net RSS