axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
916 stars 204 forks source link

Replace Vector push_back() vs emplace_back() #762

Closed aismann closed 2 years ago

aismann commented 2 years ago

push_back and emplace_back in C++ Push_back: Push_back adds a new element at the end. It first creates a temporary object by calling a constructor.

Emplace_back: It also Inserts a new element at the end. It does not create a temporary object. The object is directly created in the vector. Due to this, the efficiency is increased.

The difference in the efficiency of push_back and emplace_back depends on the type of our vector. If the vector is a built-in type, there is no difference between the efficiency of push_back and emplace_back. If the vector type is class or struct, emplace_back is more efficient than push_back.

image

see also: https://www.codingninjas.com/codestudio/library/vector-push_back-vs-emplace_back#:~:text=Push_back%3A%20Push_back%20adds%20a%20new%20element%20at%20the,vector.%20Due%20to%20this%2C%20the%20efficiency%20is%20increased.

DelinWorks commented 2 years ago

Good job! this would improve mesh generation speed since vertices get added with emplace_back rather than push_back I like it! it would be cool if IndexArray gets this change too, but I fear that POD-like (plain old data) data (i.e. floats, integers, chars) don't get this boost because they are not constructed or rather they are simple types, unlike a custom type the user created. I really don't know

DelinWorks commented 2 years ago

The difference in the efficiency of push_back and emplace_back depends on the type of our vector. If the vector is a built-in type, there is no difference between the efficiency of push_back and emplace_back. If the vector type is class or struct, emplace_back is more efficient than push_back.

Oh! sorry I didn't read that part there!

aismann commented 2 years ago

Should we change it?

DelinWorks commented 2 years ago

do you mean the Vector class with an uppercase V that holds references? if not then what array class exactly?

keep in mind that users will not adapt to this change and will instead use the default insertion method.

aismann commented 2 years ago

do you mean the Vector class with an uppercase V that holds references? if not then what array class exactly?

keep in mind that users will not adapt to this change and will instead use the default insertion method.

We change the axis engine. What users doing on here own sources is not the goal of this issue. I belive evey repace is a good idea on the axis engine sources

aismann commented 2 years ago

Have axis some tests which can show a performance boost?

DelinWorks commented 2 years ago

We change the axis engine. What users doing on here own sources is not the goal of this issue. I belive evey repace is a good idea on the axis engine sources

yeah you're right, should always consider that!

aismann commented 2 years ago

Replace push_back() vs emplace_back() on axis\core\ #781

aismann commented 2 years ago

old: push_back: image new: emplace_back: image

aismann commented 2 years ago

'extension' has also some potential: Which folder should be NOT changed? image

halx99 commented 2 years ago

The fiarygui, ImGui, Live2D, spine should be NOT changed

aismann commented 2 years ago

The fiarygui, ImGui, Live2D, spine should be NOT changed

What about DragonBones? Can be adapt?

halx99 commented 2 years ago

You aslo can skip DragonBones since it stop maintenance 4 years.

aismann commented 2 years ago

Can be closed after merge of #785.

aismann commented 2 years ago

with the extensions i got some more sprites: image