[Bf-blender-cvs] [07846b31f34] master: Cleanup: Optimize viewport view data creation

Jesse Yurkovich noreply at git.blender.org
Thu Mar 24 21:26:26 CET 2022


Commit: 07846b31f34caa88244d192ee7d3aa6c057ac602
Author: Jesse Yurkovich
Date:   Thu Mar 24 21:13:02 2022 +0100
Branches: master
https://developer.blender.org/rB07846b31f34caa88244d192ee7d3aa6c057ac602

Cleanup: Optimize viewport view data creation

Each time the user clicks the viewport 2 sets of engine views are
created. Each set is currently composed of 8 view objects, each of size
592 bytes.

Because space is not reserved in the vector that holds them, several
unnecessary re-allocation/copy cycles occur as the vector resizes and
the total allocation load is 8880 bytes. This happens twice.

Reduce to just the allocations necessary and with exactly 4736 bytes
allocated for each set
 - Before: 8 allocations and 8 deallocations totaling 17760 bytes
 - After: 2 allocations and 2 deallocations totaling 9472 bytes

Reviewed By: fclem, jbakker

Differential Revision: https://developer.blender.org/D13782

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

M	source/blender/draw/intern/draw_view_data.cc

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

diff --git a/source/blender/draw/intern/draw_view_data.cc b/source/blender/draw/intern/draw_view_data.cc
index 682728eb22b..0e55d28f6df 100644
--- a/source/blender/draw/intern/draw_view_data.cc
+++ b/source/blender/draw/intern/draw_view_data.cc
@@ -37,7 +37,10 @@ struct DRWViewData {
 
 DRWViewData *DRW_view_data_create(ListBase *engine_types)
 {
+  const int engine_types_len = BLI_listbase_count(engine_types);
+
   DRWViewData *view_data = new DRWViewData();
+  view_data->engines.reserve(engine_types_len);
   LISTBASE_FOREACH (DRWRegisteredDrawEngine *, type, engine_types) {
     ViewportEngineData engine = {};
     engine.engine_type = type;



More information about the Bf-blender-cvs mailing list