instance or objects? the best performance

Discussion and feedback on Construct 2

Post » Sat Mar 08, 2014 4:11 pm

Hi everybody, I have a doubt about the performance in general, and don't just construct2...

I means, when I'm thinking about how make some objects (sprite) for the games, o for one software, I like to make 1 object and use for many different kind of things...

it's pretty difficult to explain that (my english is not very good) but, for instance:

if we make a 2d platform game, you can make some objects for make the gameplay (like a movable platform, enemy...etc)

now, I'm making a platform in 2d, and I have one object, and this object can be a lot of object (change the frame, the variable...etc)

now, is better to have one object with 20 variable and 10 frame (and use 40 instances of the same object with different variable on the scene) or make 2 object, with 10 variable and 5 frame and use 20 instance of one and 20 instance of the another one?

what is the best system to make the best performance? is the same?

thank you very much!!
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Sat Mar 08, 2014 9:20 pm

Ribis wrote:(my english is not very good)

Image

Usually i'd try to understand what is being said, but trying to decipher what you wrote... just gives me a headache.
It's like you're not even trying. >_>

...
I'd say that making many different types of objects for different purposes would be better, as it would be easier to manage and edit, and any behaviors used wouldn't be applied to all of the objects. Probably the same for checking if conditions are true.
B
10
S
1
Posts: 163
Reputation: 1,436

Post » Sat Mar 08, 2014 9:59 pm

@Stiivais, perhaps a little too harsh with the "your second language grammar is not as good as mine" banter.... How do you know he wasn't trying?

@Ribis, as answered above - you're much better off keeping your objects and behaviors as separated as you can. It will make your project easier to understand when you look at the event sheets and will make behaviors and instance variables much easier to manage.
A big fan of JavaScript.
B
76
S
20
G
73
Posts: 2,244
Reputation: 45,962

Post » Sat Mar 08, 2014 11:11 pm

@Ribis ,Colludium,Stiivais

while its true that its probably easier to have different object, most benefit is when you want to do a compare obj a to b / for collision, placement, and like you said to split things up for behaviors, etc.., and i was always a believer that this was better

but, i recently have doubts about what gives best performance, i read on the forum, that drawcalls are per object type, but what does that mean exactly?

does that mean that if everything is in one object there's only one drawcall? does that mean that everything in a family is one drawcall? im leaning toward thinking that one single object would have the best performance, plus you have the added benefit that single objects get spritesheeted, i currently have a good way to work like this, but its more for interface work.
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Sun Mar 09, 2014 5:20 am

@vtrix,

It would be interesting to compare the performance gains / losses between using 1 instance as you say and using dozens of different instances. Without having tried it (yet) I imagine that there's a trade off where the performance gains of one way will eventually out weigh the gains of the other - such that a given layout style and number of sprites will have a range of number of instances that will give an optimum performance. I also am not sure exactly what draw calls are - are they only measured in the debugger profile page or do they also have an impact on collision checking and are indirectly measured in the event analysis?

I have a couple of embryonic games I'm working on - the intention is that I will ultimately release them on mobile and desktop, providing I can keep my focus (!), so I frequently test them both export options. Even for my most visually demanding scenes I don't see the draw calls using that much of the cpu time (up to 20% of the total cpu demand), so I simply don't worry about it yet. I frequently see that events associated with collision checking and sprite control are the most demanding so they get most of my attention...
A big fan of JavaScript.
B
76
S
20
G
73
Posts: 2,244
Reputation: 45,962

Post » Sun Mar 09, 2014 7:00 am

I have good experiences with instances + diffrent frames set instead of having multiple objects. There are some good articles from ashley about how the engine works and drawing is made.

You should optimize it only if it is needed. I focus on mobile game apps so I do a lot in that case. If you just want to make browser games I would say you are good for a long time with many objects.
B
34
S
9
G
3
Posts: 206
Reputation: 7,851

Post » Sun Mar 09, 2014 9:01 am

I'm noticed that one object and many instances better than just lot of objects.
B
57
S
19
G
10
Posts: 191
Reputation: 9,636

Post » Sun Mar 09, 2014 12:59 pm

optimizing only when needed, i understand, problem with that is, if you suddenly realize that you need extra performance, changing the way you setup things after doing all the logic is a real pita.

about testing this, it would be interesting.., most performance tests are just testing how much instances can be generated vs fps

but lets say generate 1000 instances, with one object and 1000 instances with 50 objects, i think i can test that pretty quick with nickname plugin, maybe i give that a shot later..
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Sun Mar 09, 2014 2:25 pm

Here are some results from my testing this....

So, I made a quick demo. There are 2 layouts, each with 99 custom movement objects of the same image bounded to the screen by obstacles. Layout 1 has 99 different objects while Layout 2 has 99 instances of the same object.

Draw Calls results:
99 different objects: 5.8% cpu
99 instances of same object: 2% cpu

Now.... when I delete half of the objects on each layout:
50 different objects: 3.8% cpu
50 instances of same object: 2% cpu

So there is quite an overhead for drawing different objects v the same object and a constant and significant minimum overhead on my computer at least for drawing anything on the screen. I didn't have the energy to create different images for each object to see what, if any, that sort of change might make on the draw calls. So, for my laptop at least, although the draw calls demanded 3 x the processing power to draw the different objects, the increase was still only 4% in magnitude - not a problem for most desktop games I am guessing, but such an increase could cause a slow down on a mobile device.
A big fan of JavaScript.
B
76
S
20
G
73
Posts: 2,244
Reputation: 45,962

Post » Sun Mar 09, 2014 2:40 pm

Colludium wrote:Here are some results from my testing this....

So, I made a quick demo. There are 2 layouts, each with 99 custom movement objects of the same image bounded to the screen by obstacles. Layout 1 has 99 different objects while Layout 2 has 99 instances of the same object.

Draw Calls results:
99 different objects: 5.8% cpu
99 instances of same object: 2% cpu

Now.... when I delete half of the objects on each layout:
50 different objects: 3.8% cpu
50 instances of same object: 2% cpu

So there is quite an overhead for drawing different objects v the same object and a constant and significant minimum overhead on my computer at least for drawing anything on the screen. I didn't have the energy to create different images for each object to see what, if any, that sort of change might make on the draw calls. So, for my laptop at least, although the draw calls demanded 3 x the processing power to draw the different objects, the increase was still only 4% in magnitude - not a problem for most desktop games I am guessing, but such an increase could cause a slow down on a mobile device.


Thanks for the test ;) The results are interesting
B
17
S
5
G
2
Posts: 173
Reputation: 2,085

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 1 guest