[RESEARCH] why not inline every function by default?

75 views
Skip to first unread message

JeriX

unread,
Feb 10, 2017, 6:13:34 PM2/10/17
to Haxe
maybe I don't fully understand the topic... but afaik "inline" is just a suggestion to every compiler, not only haxe
it means: if you can, please inline this function
am I right?
I mean why this keyword even exists?
at least in some release build all functions should be inlined as much as possible for performance

I understand that there is a reason for this behaviour
what I really want to ask is why is inline suggestion should be enabled by developer and not be enabled by default in the compiler

David Elahee

unread,
Feb 11, 2017, 3:32:45 AM2/11/17
to haxe...@googlegroups.com

Because it would mess with the cpu cache which may cause massive slowdowns and executable size may become huge. Inlining is to be handled with caution :)


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Porfírio Ribeiro

unread,
Feb 11, 2017, 6:13:19 AM2/11/17
to Haxe
Some times you have methods that only serve to delegate some method from a inner variable, or you have utility functions that are small like one line.
In that cases i add the inline keyword to these methods, because they don't need to exist in the generated code.
That makes the code smaller and reduce complexity.
Now if you have big methods with allot of logic that are called in many places, you are actually increasing the generated code and adding allot of complexity to the compiler to generate that code.
Still, inline is one of the features i like more on Haxe compiler.

Juraj Kirchheim

unread,
Feb 11, 2017, 9:09:32 AM2/11/17
to haxe...@googlegroups.com
Inline functions cannot be overriden (because otherwise the implementation must be chosen at runtime) and also cannot be recursive (unless they are tail recursive).

Usually 95% of the time is spent on 5% of the code and usually it's hard to find out what code that is during static analysis. Many of the runtimes Haxe targets will perform code optimization once this information becomes available during a program's execution (e.g. for classes that no subclasses or interfaces that have only one implementor). But the compiler simply is not in the position to make an informed decision. Instead, the language offers the developer the means to granularly guide the compiler. And that shouldn't really mean to stick inline all over the place but instead put it where it has the desired effect. In JS for example the resulting code size is important. Inlining can reduce code size or increase it. So whatever you optimize for, always measure the effect.

Best,
Juraj

--

JeriX

unread,
Feb 11, 2017, 9:16:53 AM2/11/17
to Haxe
thanks all of you
now I think I have better understanding of the subject and know how use inline in everyday coding ;)

Robert Konrad

unread,
Feb 11, 2017, 10:48:49 AM2/11/17
to Haxe
AFAIK C++ compilers just ignore the inline statement and decide on that themselves by the way.
In Haxe there is some additional use to inline functions in combination with inline constructors.
Reply all
Reply to author
Forward
0 new messages