0 Favourites

instance or objects? the best performance

  • 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!!

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • (my english is not very good)

    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.

  • 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.

  • 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.

  • 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...

  • 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.

  • I'm noticed that one object and many instances better than just lot of objects.

  • 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..

  • 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.

  • 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

  • Colludium , thanx for the test

    so yes, using different objects causes a slight overhead, what i find interesting is that its not a constant cycle, draw calls go as low as 0.1 (same object) and then go back to maximum calls for a while, maybe thats garbage collection and then a redraw is needed, there is also not much difference in using canvas2d for me.

    changing the object size and alpha values seems to take an extra hit, im not quite sure how drawcalls actually work.

  • 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?

    Because when i was learning english i often used google or searched for similar phrases to the ones in my native language, so that i could write a coherent and logically laid out text, and even if i got some words wrong, the people reading it could interpret it easier (and probably figure out what i meant without any hassles) because of its structure and punctuation, which doesn't differ that much between languages. Posting something like what he did just shows lack of effort, or even desire to learn the language. Criticism solves this problem.

    As for that little test of yours - drawing performance isn't what you should be testing here, but rather the way of how the event system deals with multiple instances. Set up collision checks between the different objects, have it done in such a way that there are checks done for groups of objects with different instance variables in the first test and between the different object types in the second test - just be sure to have the same amount of "groups" in both tests, e.g. 5 different instance variables and 5 different object types.

  • Stiivais

    [quote:9816sj4i]As for that little test of yours - drawing performance isn't what you should be testing here,

    great, you explain your first condescending tone and start another one...

    this was a test on drawcalls with multiple instances or multiple objects,

    but please if you want to put the effort in it, add your test, it would be interesting.

  • vtrix

    Talk to the picture, see how much it cares.

    I started making a test and i have to say that the single object approach is flawed, as there are problems when you try checking for collisions between instances. I'd like to see you manage to check for collisions between the instances of the same object - .CAPX

  • thank you all for the reply, maybe I will continue to use less object and more variable/event...

    I made a test and on mobile and is better to make more instance and change the variable to make a "new" object with the same instance (just change the frame of animation and edit the variable of the instance...) in a long time will be difficult, but is better...

    > (my english is not very good)

    >

    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.

    a lot of people understand my post, I don't like to use google translate, I just use for a new word when I don't know how I can say something new, but I wrote the first post in 3 min and for me is a good....

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)