Hey everyone,
yesterday I started fiddling around with C++ files generated by YYC (the path to the files can be found in the console upon start of running the project with YYC, for me it was C:\Users\kraif\AppData\Roaming\GameMakerStudio2\Cache\GMS2CACHE) and I found that there are situations where it produces some silly code, but since the files are available to see, we can just change our GML code accordingly to get huge performance gains.
Here is the first thing that I found.
Consider the following code.
Really simple right? Just passing a bunch of object and built-in variables to draw_sprite, in a for cycle, nothing that you wouldn't normally do and you (well or me at least) would expect that to be pretty fast. But this is what YYC generated C++ code looks like.
It actually performs a lookup for the variables (variables are stored in an array of YYRValue structures, which contain the variable value, it's type and overloaded operators to do operations like add, subtract etc. between different C++ types; variable names are just translated into a unique index within that array) inside of the loop, every iteration! And this is how it can be fixed.
We can just store the variables into local vars before the loop starts and YYC will then do the same thing. The produced code is longer, but much more clever and the performance gains are crazy - more than extra 1000fps for me! And that's just drawing a 1000 sprites in a for cycle.
I hope this helpes and I will continue playing around with it and report back again when I find more silly C++ code.
EDIT: Note: The C++ code can be also modified by hand into even better one, which in this case was another 600fps extra for me. But when you clean the cache or modify the GML code after you change the C++, it gets overwritten.
yesterday I started fiddling around with C++ files generated by YYC (the path to the files can be found in the console upon start of running the project with YYC, for me it was C:\Users\kraif\AppData\Roaming\GameMakerStudio2\Cache\GMS2CACHE) and I found that there are situations where it produces some silly code, but since the files are available to see, we can just change our GML code accordingly to get huge performance gains.
Here is the first thing that I found.
Consider the following code.
Really simple right? Just passing a bunch of object and built-in variables to draw_sprite, in a for cycle, nothing that you wouldn't normally do and you (well or me at least) would expect that to be pretty fast. But this is what YYC generated C++ code looks like.
It actually performs a lookup for the variables (variables are stored in an array of YYRValue structures, which contain the variable value, it's type and overloaded operators to do operations like add, subtract etc. between different C++ types; variable names are just translated into a unique index within that array) inside of the loop, every iteration! And this is how it can be fixed.
We can just store the variables into local vars before the loop starts and YYC will then do the same thing. The produced code is longer, but much more clever and the performance gains are crazy - more than extra 1000fps for me! And that's just drawing a 1000 sprites in a for cycle.
I hope this helpes and I will continue playing around with it and report back again when I find more silly C++ code.
EDIT: Note: The C++ code can be also modified by hand into even better one, which in this case was another 600fps extra for me. But when you clean the cache or modify the GML code after you change the C++, it gets overwritten.
Last edited: