GMS 2.3+ Are Constructor Functions expensive?

erayzesen

Member
Hi all. I'm using my custom objects via constructor functions. These cunstroctur functions have self functions.

I was testing my game with debug mode and constructor function calls are droping my game performance.

There is a big difference when I do this operation without any function or object call.

Has anyone experienced these problem after new gml updates? Is there a reason for this?
 

Joe Ellis

Member
The performance drop might be from the self functions, if they're creating the functions every time one of them is created.
It'd probably be better to create the functions per group rather than per instance, as they'd mainly be the same, just using different variables

Constructor functions themselves are supposed to be faster than creating them manually\arbitrarily in a function, as it seems to do something solid\read-only with the info while compiling.
 
Last edited:

erayzesen

Member
The performance drop might be from the self functions, if they're creating the functions every time one of them is created.
It'd probably be better to create the functions per group rather than per instance, as they'd mainly be the same, just using different variables

Constructor functions themselves are supposed to be faster than creating them manually\arbitrarily in a function, as it seems to do something solid\read-only with the info while compiling.
Thanks to reply.

For example, I made vec2 object with constructor function and it has self functions (add,subtract,normal,normalize...etc). I call this as a local variable from different instances like this;

GML:
var v1=new vec2(123,334) ;

var v2=new vec2(43,545);



var v3=v1.subtract(v2);

var v3_normal=v3.normal();

So I see this these calls are use too much memory against old game maker style codes. Shouldn't this be just as optimized as other expressions? What's the point after using this so expensive?
 

rytan451

Member
Maybe you aren't defining your methods as static? That could cause loads of data to be used. Static methods aren't static in the sense of Java or C# (where static methods are methods of a class, rather than an object). In GMS, static methods are static in the sense of C++ (defined once per function call and shared between function calls).

I've actually got an implementation of vectors linked in my signature. Feel free to take a look and use some ideas (or just copy-paste the code and use it wholesale).
 
Top