[Bf-blender-cvs] [117c990540c] soc-2020-io-performance: Optimisation: reserve memory early; use UNLIKELY

Ankit Meel noreply at git.blender.org
Mon Jun 22 21:03:37 CEST 2020


Commit: 117c990540c63d7ef738539f8633b7e571db59a3
Author: Ankit Meel
Date:   Tue Jun 23 00:25:21 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB117c990540c63d7ef738539f8633b7e571db59a3

Optimisation: reserve memory early; use UNLIKELY

Since we know the minimum number of UV vertices that a mesh can have,
its memory is reserved in advance. `append` later in the loop simply
checks whether there's sufficient space and edits the vector.

Also, in the edge writer, the last iteration is very unlikely :).

===================================================================

M	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc

===================================================================

diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
index d96e1098393..1987d51a515 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
@@ -123,6 +123,9 @@ void OBJMesh::store_uv_coords_and_indices(blender::Vector<std::array<float, 2>>
         mpoly, mloop, mloopuv, me_eval->totpoly, me_eval->totvert, limit, false, false);
 
     uv_indices.resize(me_eval->totpoly);
+    /* We know that at least totvert many vertices in a mesh will be present in its texture map. So
+     * reserve them in the start to let append be less costly later in terms of time. */
+    uv_coords.reserve(me_eval->totvert);
     ob_mesh->tot_uv_vertices = -1;
 
     for (int vertex_index = 0; vertex_index < me_eval->totvert; vertex_index++) {
@@ -196,7 +199,7 @@ void OBJMesh::calc_edge_vert_indices(blender::Array<uint, 2> &vert_indices, uint
   vert_indices[0] = edge_index + 1;
   vert_indices[1] = edge_index + 2;
   /* Last edge's second vertex depends on whether the curve is cyclic or not. */
-  if (edge_index == me_eval->totedge) {
+  if (UNLIKELY(edge_index == me_eval->totedge)) {
     vert_indices[0] = edge_index + 1;
     vert_indices[1] = me_eval->totvert == me_eval->totedge ? 1 : me_eval->totvert;
   }



More information about the Bf-blender-cvs mailing list