• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Quick Optimization Question

T

TheUnsungChampion

Guest
Hey, everyone! Quick question for those who are more knowledgeable/experienced. Is there a performance hit for calling a script rather than just running a given block of code in-line? I have found, in the course of working on my first game, that it is MUCH easier for me to keep code organized and to fix errors if I handle most things through scripts, but I want to be sure I am not affecting overall performance in an adverse way.
 

Genetix

Member
I don't believe so, You could use the debugger and try to clock it out but I doubt there is any kind of noticeable difference.
 
H

Homunculus

Guest
Just out of some prior experience, I think there is a small performance hit, but it's negligible. In my opinion having a maintainable and well structured code is invaluable, and there are for sure a lot of other areas that can be optimized with a much higher priority.

If I remember correctly you can also use gml_pragma to force some script to be compiled as inline code by the YYC
 
T

TheUnsungChampion

Guest
Wow, thank you all so much for your helpful replies! I mean, I COULD always simply "unbundle" most of my scripts once I have everything operating the way that I want, but this seems to be a simple and elegant solution to keeping everything running at top notch.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
It used to be somewhat noticeable in old versions of GameMaker, but in current versions of GMS1/GMS2 the time it takes for an extra script call is comparable to time it takes to assign a few local variables (arguments).

As mentioned, you can use the profiler to see the difference contextually, but it is rarely any noticeable improvement to not use the scripts, especially with YYC and gml_pragma("forceinline").
 
T

TheUnsungChampion

Guest
Can anyone tell me where in code the command for in-line compilation needs to be placed? Is it something I insert at the top of a script, or after the script call, or before the script call?
 
Not too long ago I did a performance test on script calls vs inline. Long story short, even pushing thing to absurd lengths, I didn't get any distinct results. sometimes script calls were faster, sometimes inline. Over the long run, that leads me to believe there's no practical difference. Mind you, I ran my tests in game, not using the profiler.
 
Top