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
This commit is contained in:
Jesse Yurkovich 2022-03-24 21:13:02 +01:00 committed by Clément Foucault
parent 3c4947cdaa
commit 07846b31f3
1 changed files with 3 additions and 0 deletions

View File

@ -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;