Inline functions

Information and change log about the latest ZGameEditor release.

Moderator: Moderators

Post Reply
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Inline functions

Post by VilleK »

New build: http://www.zgameeditor.org/files/ZGameEditor_beta.zip

You can now tag functions with the "inline" keyword to inline them.

Code: Select all

inline float min(float v1, float v2) {
	return v1 <= v2 ? v1 : v2;
}
This means that every function calling this will inline the function itself, so there is no overhead of function call and return.

The is a new option "Enable function inlining" in Project menu. When this is option is off, functions marked with "inline" will not be inlined. This is to make it easy to quickly do speed comparisons.

This works best on small functions that are called from inside a loop (so don't go and tag every function with "inline", use it carefully).

I've noticed 2x speedups on some tests using this (see attached demo which shows execution time in ms). There might be bugs so please test.
Attachments
inlinetest.zgeproj
(2.05 KiB) Downloaded 843 times
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Inline functions

Post by rrTea »

Running certain projects in Preview breaks closing of ZGE. I'm getting the following messages when I try to exit:
[attachment=2]剪貼簿圖片 (6).png[/attachment]

...after which this one pops up:
[attachment=1]剪貼簿圖片 (7).png[/attachment]

If I try to open a new file:
[attachment=0]剪貼簿圖片 (8).png[/attachment]

Simple programs don't cause this (for example the file from the first post) but some projects do.

Ray
(Edit: sorry I don't have the option of turning the BBCode on in this part of the forum)
Attachments
Can't load a file
Can't load a file
剪貼簿圖片 (8).png (1.42 KiB) Viewed 23555 times
Second message
Second message
剪貼簿圖片 (7).png (2.09 KiB) Viewed 23555 times
First message...
First message...
剪貼簿圖片 (6).png (1.62 KiB) Viewed 23555 times
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Inline functions

Post by VilleK »

Thanks for testing, this should be fixed now: http://www.zgameeditor.org/files/ZGameEditor_beta.zip
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Flooding the console

Post by rrTea »

The current build prints out the whole ZGE project to console every time a project is loaded or launched in Preview. This is not such a big deal for smaller projects but it's slowing things down a bit if a project is a bit bigger. In addition - one thing I do before running the project through preview is clearing of the console, which makes the whole process even slower. Here is what it looks like:
[attachment=0]Capture-025.avi[/attachment]

In the recording I'm opening the project, and then launch it - note how much slower it is than the usual ZGE speed (which is very fast ;) ). Clearing of the console happens at 00:20.
Attachments
Capture-025.avi
Load + launch
(2.01 MiB) Downloaded 656 times
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Flooding the console

Post by VilleK »

rrTea wrote:The current build prints out the whole ZGE project to console every time a project is loaded or launched in Preview.
Aha, sorry this was debug info I forgot to exclude. Fixed now. Please download again.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Inline functions

Post by VilleK »

Another important advantage of inline functions is when one or several of the arguments to a function is a constant, this adds more opportunities for optimization.

Using the function "min" from above:

Code: Select all

float x=min(1,2);
After inlining the compiler transforms to this:

Code: Select all

float x=1 <= 2 ? 1 : 2;
Then it notices the whole expression is now constant so it simplifies to just this:

Code: Select all

float x=1;
This works with all constants: literals ("1" etc), "const" variables, and Constant components. And constant expressions ("1+2" etc).
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: Inline functions

Post by Rado1 »

inline keyword could be highlighted in editor as other keywords.
Post Reply