Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you measured that the speed problem is really caused by <code>Convert.ToSingle</code>?</p> <p>In the code you included, I see you create lists and dictionaries like this:</p> <pre><code>normals = new List&lt;Vector3&gt;(); texCoords = new List&lt;Vector2&gt;(); objVerticesIndexDictionary = new Dictionary&lt;ObjMesh.ObjVertex, int&gt;(); </code></pre> <p>And then when you read the file, you add in the collection <strong>one item at a time</strong>. One of the possible optimizations would be to save total number of normals, texCoords, indexes and everything at the start of the file, and then initialize these collections by these numbers. This will pre-allocate the buffers used by collections, so adding items to the them will be pretty fast.</p> <p>So the collection creation should look like this:</p> <pre><code>// These values should be stored at the beginning of the file int totalNormals = Convert.ToInt32(textReader.ReadLine()); int totalTexCoords = Convert.ToInt32(textReader.ReadLine()); int totalIndexes = Convert.ToInt32(textReader.ReadLine()); normals = new List&lt;Vector3&gt;(totalNormals); texCoords = new List&lt;Vector2&gt;(totalTexCoords); objVerticesIndexDictionary = new Dictionary&lt;ObjMesh.ObjVertex, int&gt;(totalIndexes); </code></pre> <p>See <a href="http://msdn.microsoft.com/en-us/library/dw8e0z9z.aspx" rel="nofollow">List&lt;T&gt; Constructor (Int32)</a> and <a href="http://msdn.microsoft.com/en-us/library/tk84bxf4.aspx" rel="nofollow">Dictionary&lt;TKey, TValue&gt; Constructor (Int32)</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload