Functions inefficient *

Discussion and feedback on Construct 2

Post » Thu Nov 12, 2015 11:27 pm

i've done my testing in debugger
1st test - 1% cpu
2nd test - 3% cpu
3rd test - 3% cpu
4th test - 3% cpu
5th test -5-6% cpu
6th test - 20% CPU - uses function
7th test - 24% CPU - uses function
8th test - 24% CPU - uses function

so i've ran the benchmark he gave, but this seems very odd to me. 25% CPU ? that's one CORE - also that last test never stops, so your code might be buggy (i'll check in more detail tommorow). Also i've got 4860M (quad 3.6GHz) and eating 25% with functions is wtf. I mean i've made a game / template / with long and loads of functions (check link in my signature) and i've never went over 15% while playin, only when loads of particles went on screen - then i'd go up to 70%. But going over 15% with functions... i'm pretty positive your code is buggy :)
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

Post » Thu Nov 12, 2015 11:59 pm

No long in-call loops, no every tick triggers, seems fairly reasonable.

I generally try to avoid them anyway.
A variable comparison, while harder to set up, should perform even better.
Image ImageImage
B
168
S
50
G
163
Posts: 8,223
Reputation: 105,065

Post » Fri Nov 13, 2015 12:27 am

@newt - For sure, if I understand what you mean by setting up a variable comparison, I do that lots now. conditions = set variable to 1. After that check the variable, if it is 1 then do stuff, or similar setups.

My biggest trouble is that I've noticed you need* "for each family loop"s with multiple function calls for scaleability. When functions are used as a design element to make your game scalable and manageable. For example, in my game, every dynamic object affected by world forces (gravity, wind, etc) is in a family called characters. The player, bullets, enemies, etc, are all in this family and this family must call 3-4 functions minimum but may call more. If you only have a few characters, no problem, but for every function I add, I exponentially impact my performance. Knowing this, I design more around less function calls. I'll see what my performance is in the end before taking drastic measures though :)
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Fri Nov 13, 2015 12:57 am

whaaaat?? I get 54% cpu usage for the functions, and about 7-10% without.
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Sat Apr 29, 2017 4:49 pm

Just ran into this issue again.. I had an event that was using 0.1% cpu, and when put in a function it became 1.5%
That's a 1500% increase just because it was put in a function!
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Mon May 08, 2017 4:32 pm

What happens if you compile with minify ?

I ask because according to Ashley the minify/obfuscate option on compile uses Google's Closure Compiler in advanced mode.

and according to Google info, the advanced mode goes through looking for simple functions and "inlines" them.

So if the functions as used in events appear as functions in the JS output then maybe these types of simple functions will not even be functions in compiled code.

"....Compilation with ADVANCED_OPTIMIZATIONS replaces the call to displayNoteTitle() with the single alert() that composes the function's body. This replacement of a function call with the function's body is known as "inlining". If the function were longer or more complicated, inlining it might change the behavior of the code, but the Closure Compiler determines that in this case inlining is safe and saves space. Compilation with ADVANCED_OPTIMIZATIONS also inlines constants and some variables when it determines that it can do so safely...."

https://developers.google.com/closure/compiler/docs/api-tutorial3
...
B
42
S
21
G
7
Posts: 260
Reputation: 7,683

Post » Mon May 08, 2017 6:48 pm

I have worked on procedural generation and implemented the Perlin Noise algorithm in C2 in events and in javascript code
I found out that javascript is much faster than events, just a fact
B
42
S
17
G
17
Posts: 2,247
Reputation: 17,461

Post » Mon May 08, 2017 7:43 pm

One possible explanation would be events are not converted to JavaScript, instead they are converted to a bytecode of sorts that is interpreted by the runtime which in turn calls the functions in plugins and the runtime. CC did basically the same thing.

Now JavaScript engines are really good at analyzing js code and generating fast machine machine code on the fly. That's how js performance can often rival a compiled language. My thought is the events bytecode is basically data and the javascript engine is unable to streamline the data as it does code.

A fairly complicated solution could be to compile the event sheet to javascrict. Sounds simple but probably is a huge can of worms.
B
91
S
31
G
103
Posts: 5,234
Reputation: 67,754

Previous

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 12 guests