• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Discussion instance_create_empty(object); ?! for data!!

xDGameStudios

GameMaker Staff
GameMaker Dev.
As far as it looks like... an object is a kind of ds_map, but with a lot of pre-built stuff in it...
we could make it look like a data holder if we do something like

var a = instance_create_depth(0, 0, 0, object_data)
instance_deactivate(a);

and then use "a" just for data storage;
and it would be easier to access variables like this a.weapon.attack (where weapon is another object);

but then again a lot of builtin variables are there and.. it uses more memory... :/

what if we could disable (deactivate) the update/draw/(and every other event) and make the object "empty" with no variables at all... other than the ones defined within the create event of the object?? it would no be needed to place the object in a x and y because it would not be drawn... is for data only!! ;)

this would be the closest thing to a OO class design... is it too bad?! (sorry if it is.. just though it would be a good ideia) :)

PS: another thing... accessing a none existing variable... example: a.adsfsdf (could result in a: undefined).. much like it happens with javascript (like a json object).
 

csanyk

Member
Interesting...

Although, I think, if you're that worried about a single instance's overhead killing the performance of your game enough that you need to worry about disabling it, that's pretty extreme. What do you really gain by disabling it, really? How many fps do you get back? It's got to be near zero, right?

I've used objects like this, without disabling them, and it works just fine, and I can even use the object's draw event, step event, etc. to do other stuff I need done anyway (like draw a dashboard, etc.)
 

GMWolf

aka fel666
Interesting...

Although, I think, if you're that worried about a single instance's overhead killing the performance of your game enough that you need to worry about disabling it, that's pretty extreme. What do you really gain by disabling it, really? How many fps do you get back? It's got to be near zero, right?

I've used objects like this, without disabling them, and it works just fine, and I can even use the object's draw event, step event, etc. to do other stuff I need done anyway (like draw a dashboard, etc.)
Actually when creating larger data structurs, objects simply arnt viable as they are right now!
I like building graphs for path finding. Using GM object would use way too much memory and the extra overhead kills performance. I have to use array structs instead. I problem i never have in other languages.


I dont think creating empty objects is the solution however. What would be great to have instead are structs. They would essentially be empty instances, but they could never be the calling instance.
They would not have types either. Much like GMObjects, you could store any variable in them at any time.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
Interesting...

Although, I think, if you're that worried about a single instance's overhead killing the performance of your game enough that you need to worry about disabling it, that's pretty extreme. What do you really gain by disabling it, really? How many fps do you get back? It's got to be near zero, right?

I've used objects like this, without disabling them, and it works just fine, and I can even use the object's draw event, step event, etc. to do other stuff I need done anyway (like draw a dashboard, etc.)
is not a "single" instance... what if you have 200 items and you want to store the item data using objects (for example).... you would need to create 200 instances and it would be a hell of a performance issue.


Actually when creating larger data structurs, objects simply arnt viable as they are right now!
I like building graphs for path finding. Using GM object would use way too much memory and the extra overhead kills performance. I have to use array structs instead. I problem i never have in other languages.


I dont think creating empty objects is the solution however. What would be great to have instead are structs. They would essentially be empty instances, but they could never be the calling instance.
They would not have types either. Much like GMObjects, you could store any variable in them at any time.
I like that ideia.... but "they could never be the calling instance"?! what do you mean by that? I didn't understand!
 

csanyk

Member
is not a "single" instance... what if you have 200 items and you want to store the item data using objects (for example).... you would need to create 200 instances and it would be a hell of a performance issue.
I suppose it would be, but I don't understand why you'd create so many instances. A single instance can store an array or DS full of data to manage data pertaining to as many objects/instances as you please.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
I suppose it would be, but I don't understand why you'd create so many instances. A single instance can store an array or DS full of data to manage data pertaining to as many objects/instances as you please.
the ideia here was to create an empty object and then being able to access its data.. like so: party.actor1.hands.equipment.attack
where actor would be an object, actor1 would be an object, hands would be an object, equipment would be an object, and attack would be the variable

this is not something that can't be done with data structures... this way it would be easier..

herb = instance_create(x,y,depth,obj_usable);
herb.heal_effect = 10;
herb.scope = scopes.all;
herb.target = targets.ally;
herb.cost = 100;
herb.can_break = false;
herb.graphics = instance_create(x,y,depth,obj_graphics);
herb.graphics.icon = 1;

is more intuitive then:

herb[? "heal_effect"] = 10;
herb[? "scope"] = scopes.all;
herb[? "target"] = targets.ally;
herb[? "cost"] = 100;
herb[? "can_break"] = false;

it would even be possible to create methods for objects this way
and the best part of it ...parenting...

herb is an usable, usable is a type of item... and this way you could check if the herb is usable looking at its parents... ;)
 
Last edited:

csanyk

Member
the ideia here was to create an empty object and then being able to access its data.. like so: party.actor1.hands.equipment.attack
where actor would be an object, actor1 would be an object, hands would be an object, equipment would be an object, and attack would be the variable

this is not something that can't be done with data structures... this way it would be easier..
Hmm, well if you want a deep hierarchy like that, then maybe I can see the point in using a lightweight nested data structure instead of nesting instances within variables in other objects. I agree it would be easier to do by nesting instances, since the dot operator is very easy syntax to use, and GML ds_ functions are a bit harder to use. So I can see the merit in the approach.

I'm still surprised that having a lot of empty instances that have no events defined, only properties defined, would incur a lot of overhead.

I've written demos where I had tens of thousands of empty instances sitting in my game, doing nothing but sitting there, drawing their sprite, and had good performance (on Windows YYC) up to around 50k instances, and that was on a 2.0 GHz Core 2 Duo CPU from 8 years ago. So I'm still skeptical that having merely hundreds of instances, using only variables to store info in an organized hierarchy as you're intending, would create a lot of overhead.

Generally, I don't believe that an empty Event gets compiled at all, so should not incur extra overhead.

And if you wanted to, you can deactivate the draw event by making the object invisible.

Again, the built-in variables would use a little extra RAM per instance, and I guess that could add up, but again, I've had thousands of empty instances sitting in a room, and still had excellent fps.

And, as you suggest, you could deactivate the instances, while still being able to access its instance variables, to completely eliminate any performance stolen by having hundreds of active instances.

So, you'd still have a little bit of extra RAM per instance cosumed by the built-in variables, but this is pretty miniscule, and very little (almost none) CPU taken up by deactivated instances.

At least, that's my best guess. Seems like a good approach to take. Give it a try and benchmark it, and come back with your findings :)
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
100000 intances will make my fps counter drop from 3000fps to 60fps (even if I deactivate them) they are not being drawn or updated or anything else and still it is a huge overhead... so... *the way it is right now*... they are not a good ideia to store data.
 

csanyk

Member
100000 intances will make my fps counter drop from 3000fps to 60fps (even if I deactivate them) they are not being drawn or updated or anything else and still it is a huge overhead... so... *the way it is right now*... they are not a good ideia to store data.
I've never had that many instances active at once. I am surprised to hear that they reduce fps even when deactivated, and now I'm curious as to why that is.

That said, I don't know that spawning 100000 instances is necessarily a valid test case. I would think something closer to typical use would be a better way to test. In situations where I've used an object as a sort of general data manager/storage for my game, I've always used just one instance, and obviously the overhead from a single instance isn't a concern to anyone. I could see things getting out of hand with several hundred or thousand instances... but in practice in my games I've rarely exceeded 500-1000 instances (and yeah, I did need to figure out a few optimization tricks to get that many instances working, but they were active and doing stuff, including slow collision checks). In a baseline performance test that I ran years ago when YYC was first released I've had tens of thousands of active instances doing nothing, and held fps > 30 or 60, and that was on fairly old hardware.

Of course you never want to have more instances than you need. If you think you need anywhere near 1000000 instances to store data for all your stuff, you probably are on the wrong approach, or else building something far more massive than GMS is intended to handle. For dealing with that many active instances, I would think you'd want to look into an engine that supports multi-threading, so you can benefit from modern multi-core CPUs.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
I've never had that many instances active at once. I am surprised to hear that they reduce fps even when deactivated, and now I'm curious as to why that is.

That said, I don't know that spawning 100000 instances is necessarily a valid test case. I would think something closer to typical use would be a better way to test. In situations where I've used an object as a sort of general data manager/storage for my game, I've always used just one instance, and obviously the overhead from a single instance isn't a concern to anyone. I could see things getting out of hand with several hundred or thousand instances... but in practice in my games I've rarely exceeded 500-1000 instances (and yeah, I did need to figure out a few optimization tricks to get that many instances working, but they were active and doing stuff, including slow collision checks). In a baseline performance test that I ran years ago when YYC was first released I've had tens of thousands of active instances doing nothing, and held fps > 30 or 60, and that was on fairly old hardware.

Of course you never want to have more instances than you need. If you think you need anywhere near 1000000 instances to store data for all your stuff, you probably are on the wrong approach, or else building something far more massive than GMS is intended to handle. For dealing with that many active instances, I would think you'd want to look into an engine that supports multi-threading, so you can benefit from modern multi-core CPUs.

I said they were deactivated... if so... 100000... or 1000000000... would be just a problem of more memory.. not CPU usage... or am I wrong?!
creating a lot (and I really mean a lot) of instances is the only way to really test if they have an impact in the cpu usage... and they have... even if it's only 1.
 

csanyk

Member
I said they were deactivated... if so... 100000... or 1000000000... would be just a problem of more memory.. not CPU usage... or am I wrong?!
creating a lot (and I really mean a lot) of instances is the only way to really test if they have an impact in the cpu usage... and they have... even if it's only 1.
It depends on what type of testing you are trying to accomplish.

If you're trying to find the limits of the engine, then a stress test like this is fine. But if it doesn't simulate your real-world expected use of the engine, then what's the point? If the real-world use case works acceptably, if you're hitting your fps goal, isn't "good enough" good enough?

Don't get me wrong, I love to figure out the most efficient way to do stuff, but that is both at run time and at dev time. If I have to go through contortions at dev time to gain efficiency at runtime that I don't need, I won't bother. If I need it, I'll do it.

Show me a game that isn't some kind of MMORPG that requires 10^5 instances, then I'll be more concerned about the result; otherwise, it's merely interesting for academic concerns :)
 
I

icuurd12b42

Guest
I think they added named array elements to gml. which basically would accomplish what you ask
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
It depends on what type of testing you are trying to accomplish.

If you're trying to find the limits of the engine, then a stress test like this is fine. But if it doesn't simulate your real-world expected use of the engine, then what's the point? If the real-world use case works acceptably, if you're hitting your fps goal, isn't "good enough" good enough?

Don't get me wrong, I love to figure out the most efficient way to do stuff, but that is both at run time and at dev time. If I have to go through contortions at dev time to gain efficiency at runtime that I don't need, I won't bother. If I need it, I'll do it.

Show me a game that isn't some kind of MMORPG that requires 10^5 instances, then I'll be more concerned about the result; otherwise, it's merely interesting for academic concerns :)
if you create 100000 ds_maps... fps don't drop.. because ds_maps do not interfere with CPU... if you create 100000 objects even if they are deactivated... they slow down the engine... so there is overhead... that's what I'm trying to say... so if there is only 1 deactivated object it still slows down the system.. just because you don't see it.. doesn't mean it doesn't exist... and if you create an entire RPG database with all items and actors and weapons and armor and states and enemies defined as objects (just to store data... not a list with everything inside).. then there will be a lot of objects defined..and so they will slow down ;)
 

Juju

Member
Really? That surprises me. I'd like to know why/how this is so, if you or anyone else happens to know why.
Can confirm. When I was making this I originally started with an object-based approach (one object per triangle on the globe model during recursive subdivision). I refactored it to a data structure architecture and got an order of magnitude better performance (during generation). For large datasets, the overhead for creating/destroying instances and grabbing data from inside instances starts to become significant. Note that this is nothing to do with CPU load during gameplay, this is purely data management.

I've experienced this in other places as well, namely node-based pathfinding on even modestly-sized maps, where the extra CPU time spent managing instances adds up in addition to other costs. GM is not OOP and you can't use objects in the same way, unfortunately.
 
Last edited:
T

trebor777

Guest
So for someone coming from OOP,
what's the simplest way to achieve this (despite the obvious, using a GMObject) ?
 

babyjeans

Member
It's interesting to me that Objects that have no events and no sprites or are even disabled still have a per-frame overhead. What exactly is it doing per each object per frame?
 
T

TimothyAllen

Guest
if you create 100000 ds_maps... fps don't drop.. because ds_maps do not interfere with CPU... if you create 100000 objects even if they are deactivated... they slow down the engine... so there is overhead... that's what I'm trying to say... so if there is only 1 deactivated object it still slows down the system.. just because you don't see it.. doesn't mean it doesn't exist... and if you create an entire RPG database with all items and actors and weapons and armor and states and enemies defined as objects (just to store data... not a list with everything inside).. then there will be a lot of objects defined..and so they will slow down ;)
Sounds like people are just talking out of their... If you deactivate an instance it WILL NOT (in my experience and interpretation of the manual) affect the fps of your game. Yes it will eat up memory because instances have lots of predefined data in them, but ironically enough, ds_maps take up WAY WAY more memory than an instance does. My rule of thumb is if I need lots of mini data containers I use arrays. If for some reason arrays is too messy, I move to instances (deactivated) because moving to ds_ data structures does not save on memory usage nor performance and in fact accessing an instance variable is faster than accessing a ds_ element (from my experience). If using deactivated instances though, you need to take care if you are also deactivating / activating other instances (not simple data containers).

Short story even shorter. Its not a good idea to use the ds_ data structures for lots of mini data containers especially ds_maps... holy 💩💩💩💩 they take up lots of memory.

Oh and to be clear, I would really love c style struct data containers as well

EDIT: Just did a test (in GMS1 so perhaps something has changed in GMS2)
Room started with one object in it.
Pressed space to create 100,000 instances that get deactivated.
FPS remains the same.
Create another 100,000.
FPS remains the same.
Repeated up to having 500,000.
FPS stayed in the 1500-2000 range which is where it was with one object.
 
Last edited by a moderator:

xDGameStudios

GameMaker Staff
GameMaker Dev.
Sounds like people are just talking out of their... If you deactivate an instance it WILL NOT (in my experience and interpretation of the manual) affect the fps of your game. Yes it will eat up memory because instances have lots of predefined data in them, but ironically enough, ds_maps take up WAY WAY more memory than an instance does. My rule of thumb is if I need lots of mini data containers I use arrays. If for some reason arrays is too messy, I move to instances (deactivated) because moving to ds_ data structures does not save on memory usage nor performance and in fact accessing an instance variable is faster than accessing a ds_ element (from my experience). If using deactivated instances though, you need to take care if you are also deactivating / activating other instances (not simple data containers).

Short story even shorter. Its not a good idea to use the ds_ data structures for lots of mini data containers especially ds_maps... holy **** they take up lots of memory.

Oh and to be clear, I would really love c style struct data containers as well

EDIT: Just did a test (in GMS1 so perhaps something has changed in GMS2)
Room started with one object in it.
Pressed space to create 100,000 instances that get deactivated.
FPS remains the same.
Create another 100,000.
FPS remains the same.
Repeated up to having 500,000.
FPS stayed in the 1500-2000 range which is where it was with one object.


As you can see... I'm getting 32 fps .. :(
I'm not as lucky as you! if you can share the project with us, I would be grateful... maybe I'm doing something wrong :/

Code:
global.b = []

var  i = 0
repeat (100000) {
    global.b[i] = instance_create_depth(....);
    i++;
}

// the object I'm creating deactivates itself in creation code ;)
 
Last edited:

xDGameStudios

GameMaker Staff
GameMaker Dev.
Well what i was asking was... a function called for example:

Code:
struct_create();
this would create a object-ish structure...

1) with no build-in variables
2) deactivated
3) no graphics
4) and accessed as a object would ex: struct.variable = value; [...] and value = struct.variable;
5) accessing an non-existing variable would return ... undefined (for example);
6) would have no impact with fps
7) I may need to be destroyed ex: struct_destroy(id);

is it possible?! (administrators!?... Mike!?) ;)

thank you for your time!
 
T

TimothyAllen

Guest
Let me do test in GM2. As i stated, i did this in GMS1 (since i dont use GMS2 for projects yet). Its very possible that something has changed. Which wouuld suck if they dont provide structs like objects in the future.

EDIT: Yeah, deactivating instances in GMS2 seem broken. This is likely a bug since this is stated in the manual for GMS2
GameMaker Studio 2 offers you the possibility to "switch off" instances so that they are no longer processed in any way. Technically they don't really exist anymore, except as a pointer within the deactivation process itself, which means that a deactivated instance cannot be manipulated or changed in any way at all until it is re-activated again. So, these functions should be used with great care as they can cause problems when not used properly, particularly with persistent objects, as a persistent object that has been deactivated will not be moved to the next room unless it is re-activated first (effectively deleting it from the game).
 
Last edited by a moderator:

Juju

Member
what's the simplest way to achieve this (despite the obvious, using a GMObject) ?
Either a map (each key is a member) or an array indexed by an enum (each element is a member). I tend to use the latter.

If you deactivate an instance it WILL NOT (in my experience and interpretation of the manual) affect the fps of your game.
Example GMS1 project. I cannot get up to 100k empty instances without the FPS tanking. If you're going to make performance claims, you must provide a project. (Also gonna tag @babyjeans and @xDGameStudios here.)

Code:
YYC:
50,000 instances = 59FPS
half deactivated = ~140FPS

75,000 instances = 36FPS
half deactivated = ~88FPS

100,000 instances = 28FPS
half deactivated = 60FPS

VM:
50,000 instances = 58FPS
half deactivated = ~130FPS

75,000 instances = 38FPS
half deactivated = ~84FPS

100,000 instances = 27FPS
half deactivated = 55FPS
 
T

TimothyAllen

Guest
Either a map (each key is a member) or an array indexed by an enum (each element is a member). I tend to use the latter.


Example GMS1 project. I cannot get up to 100k empty instances without the FPS tanking. If you're going to make performance claims, you must provide a project. (Also gonna tag @babyjeans and @xDGameStudios here.)

Code:
YYC:
50,000 instances = 59FPS
half deactivated = ~140FPS

75,000 instances = 36FPS
half deactivated = ~88FPS

100,000 instances = 28FPS
half deactivated = 60FPS

VM:
50,000 instances = 58FPS
half deactivated = ~130FPS

75,000 instances = 38FPS
half deactivated = ~84FPS

100,000 instances = 27FPS
half deactivated = 55FPS
why are you only deactivating half? I can have as many deactivated instances as I can hold in memory and see no performance drop. I would say your data also confirms that. You show that having 50k active instances gives the same FPS as 100k instances where only half are active (aka 50k). Which means the 50k inactive instances aren't effecting FPS at all. When I get back to my PC I can upload a project if you like, but not much of a point since someone can easily write a few lines of code and get the same results.
 

Mike

nobody important
GMC Elder
exactly 30fps is a suspicious number.....

1) Have you increased the FPS in the Game Options? its 30 by default.
2) VBlank Synchronisation on?
3) ms sleep timer still at 1? Stick it to 10....
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
exactly 30fps is a suspicious number.....

1) Have you increased the FPS in the Game Options? its 30 by default.
2) VBlank Synchronisation on?
3) ms sleep timer still at 1? Stick it to 10....

not exactly 30fps... I posted a picture in this post... with an array with 100000 deactivated objects and as you can see... the frame rate is 32fps.... it stays there... between 27fps and 40fps!! GMS1... didn't have this problem.. it stayed in the 3000fps... is it ok for deactivated objects to interfere with fps?
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
So for someone coming from OOP,
what's the simplest way to achieve this (despite the obvious, using a GMObject) ?
I had recently asked about a similar thing, which brought up a bit of a discussion including a fancy workaround.
So what I have now is making "structure prototypes",
Code:
global.point_proto = [undefined, "x", 0, "y", 0];
#macro point_x 2
#macro point_y 4
which define field names (for viewing in debugger), and in "constructor" script there is
Code:
/// point_create(x, y)
var p = global.point_proto;
p[0] = "point"; // makes a copy of array
p[point_x] = argument0;
p[point_y] = argument1;
with further writes being through [@] accessor to avoid copy-on-write behaviour.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
I had recently asked about a similar thing, which brought up a bit of a discussion including a fancy workaround.
So what I have now is making "structure prototypes",
Code:
global.point_proto = [undefined, "x", 0, "y", 0];
#macro point_x 2
#macro point_y 4
which define field names (for viewing in debugger), and in "constructor" script there is
Code:
/// point_create(x, y)
var p = global.point_proto;
p[0] = "point"; // makes a copy of array
p[point_x] = argument0;
p[point_y] = argument1;
with further writes being through [@] accessor to avoid copy-on-write behaviour.
One could even do something like this:

Code:
#macro point_proto ["point", "x", 0, "y", 0]
#macro point_x 2
#macro point_y 4
and then just use the point_proto macro :)

Code:
/// point_create(x, y)
var p = point_proto;
// p[0] = "point"; --> this is not needed to create a new!
p[point_x] = argument0;
p[point_y] = argument1;
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
One could even do something like this:

Code:
#macro point_proto ["point", "x", 0, "y", 0]
#macro point_x 2
#macro point_y 4
and then just use the point_proto macro :)

Code:
/// point_create(x, y)
var p = point_proto;
// p[0] = "point"; --> this is not needed to create a new!
p[point_x] = argument0;
p[point_y] = argument1;
There was a good reason to using copy-on-write behaviour - try comparing performance of two,
Code:
var n = 100000, t, q;
#macro point_mcr ["point", "x", 0, "y", 0]
#macro point_x 2
#macro point_y 4
global.point_proto = [undefined, "x", 0, "y", 0];
//
t = get_timer();
repeat (n) {
    q = undefined;
    q = global.point_proto;
    q[0] = "point";
    q[point_x] = 1;
    q[point_y] = 2;
}
show_debug_message(get_timer() - t);
//
t = get_timer();
repeat (n) {
    q = undefined;
    q = point_mcr;
    q[point_x] = 1;
    q[point_y] = 2;
}
show_debug_message(get_timer() - t);
on VM, output is 70K and 144K accordingly.
on YYC, output is 20K and 115K accordingly.

Or, for better\averaged subjectivity:
http://yal.cc/get/xm/lang/struct-tests.yyz
I've also added a 10-field structure for a good measure of where things are going.

VM:
upload_2016-12-25_5-26-30.png
As can be seen, "prototype" approach starts off 2x faster at 2-field structure and gradually drifts apart as you add more fields, coming to 4x difference at 10 fields.

YYC:
upload_2016-12-25_5-27-43.png
Initial difference is more noticeable (6x) and difference gap grows faster, coming to 17x difference at 10 fields.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
There was a good reason to using copy-on-write behaviour - try comparing performance of two,
Code:
var n = 100000, t, q;
#macro point_mcr ["point", "x", 0, "y", 0]
#macro point_x 2
#macro point_y 4
global.point_proto = [undefined, "x", 0, "y", 0];
//
t = get_timer();
repeat (n) {
    q = undefined;
    q = global.point_proto;
    q[0] = "point";
    q[point_x] = 1;
    q[point_y] = 2;
}
show_debug_message(get_timer() - t);
//
t = get_timer();
repeat (n) {
    q = undefined;
    q = point_mcr;
    q[point_x] = 1;
    q[point_y] = 2;
}
show_debug_message(get_timer() - t);
on VM, output is 70K and 144K accordingly.
on YYC, output is 20K and 115K accordingly.

Or, for better\averaged subjectivity:
http://yal.cc/get/xm/lang/struct-tests.yyz
I've also added a 10-field structure for a good measure of where things are going.

VM:
View attachment 5552
As can be seen, "prototype" approach starts off 2x faster at 2-field structure and gradually drifts apart as you add more fields, coming to 4x difference at 10 fields.

YYC:
View attachment 5553
Initial difference is more noticeable (6x) and difference gap grows faster, coming to 17x difference at 10 fields.
woooow :O I really didn't think it would make that much of a difference...or any at all... do you know why that happens?!
great test, I'll have that in mind in the future :)
You could write a book on GML :) I would be the first to buy! xD
 
I

icuurd12b42

Guest
interesting but would it be slightly faster if

global.point_proto = ["point", "x", 0, "y", 0];

...

var p = global.point_proto;
//p[0] = "point"; // superfluous
p[point_x] = argument0; // makes a copy of array and set
p[point_y] = argument1; // set... possibly p[@point_y] = argument1;
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
interesting but would it be slightly faster if

global.point_proto = ["point", "x", 0, "y", 0];

...

var p = global.point_proto;
//p[0] = "point"; // superfluous
p[point_x] = argument0; // makes a copy of array and set
p[point_y] = argument1; // set... possibly p[@point_y] = argument1;
There are two reasons to using that construct:
  1. Safety measure: you will not risk corrupting the prototype if you don't happen to [] set any fields inside the constructor script.
  2. On VM, there's a small check inserted before the first [] assignment in the script, meaning that
    Code:
    /// array_decl_w(...)
    var r;
    r[0] = argument[0];
    for (var i = 1; i < argument_count; i++) {
        r[i] = argument[i];
    }
    return r;
    is a little bit faster than
    Code:
    /// array_decl(...)
    var r;
    for (var i = 0; i < argument_count; i++) {
        r[i] = argument[i];
    }
    return r;
    Shown are comparisons with 1, 2, 3, and 4 arguments accordingly:
    upload_2016-12-25_8-55-26.png
 
Top