Inline functions

Information and change log about the latest ZGameEditor release.

Moderator: Moderators

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

Inline functions

Postby VilleK » Thu Jan 11, 2018 1:18 pm

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.16 KiB) Downloaded 108 times

User avatar
rrTea
Posts: 320
Joined: Sat Feb 15, 2014 9:54 am

Re: Inline functions

Postby rrTea » Fri Jan 12, 2018 3:01 am

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
剪貼簿圖片 (8).png
Can't load a file
剪貼簿圖片 (8).png (1.42 KiB) Viewed 1692 times
剪貼簿圖片 (7).png
Second message
剪貼簿圖片 (7).png (2.1 KiB) Viewed 1692 times
剪貼簿圖片 (6).png
First message...
剪貼簿圖片 (6).png (1.63 KiB) Viewed 1692 times

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

Re: Inline functions

Postby VilleK » Fri Jan 12, 2018 12:28 pm

Thanks for testing, this should be fixed now: http://www.zgameeditor.org/files/ZGameEditor_beta.zip

User avatar
rrTea
Posts: 320
Joined: Sat Feb 15, 2014 9:54 am

Flooding the console

Postby rrTea » Sat Jan 13, 2018 10:22 am

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.02 MiB) Downloaded 79 times

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

Re: Flooding the console

Postby VilleK » Sat Jan 13, 2018 10:57 am

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: 1918
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Inline functions

Postby VilleK » Sun Jan 14, 2018 7:46 pm

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: 770
Joined: Wed May 05, 2010 12:16 pm

Re: Inline functions

Postby Rado1 » Sun Jan 28, 2018 10:17 am

inline keyword could be highlighted in editor as other keywords.


Return to “Releases”

Who is online

Users browsing this forum: No registered users and 0 guests