Sunday, 15 April 2012

optimization - Do I need to worry about inlining in Unity/C#? -



optimization - Do I need to worry about inlining in Unity/C#? -

for code clarity create function should inlined, either wrapper, or function called in single point, or short function supposed called , fast.

in c inline without sec thought, in unity/c# there's no way afaik (this appears available @ .net 4.5).

can trust compiler smart plenty inline smartly, or i'd improve sacrifice code clarity performance, mistrusting compiler?

sure depends case case, premature optimization evil, , should profile instead of guessing. general overview of subject might still useful guideline, improve upon.

manually forcing in-lining in c# @ compile time doesn't create much sense. when code run just-in-time compiler can decide in-line code based on these heuristics:

http://blogs.msdn.com/b/ericgu/archive/2004/01/29/64717.aspx

methods greater 32 bytes of il not inlined. virtual functions not inlined. methods have complex flow command not in-lined. complex flow command flow command other if/then/else; in case, switch or while. methods contain exception-handling blocks not inlined, though methods throw exceptions still candidates inlining. if of method's formal arguments structs, method not inlined.

if you're absolutely sure method has in-lined can utilize these above heurstics create method more appealing in-line.

methodimploptions.aggressiveinlining useful inlining across assembly boundaries, not believe just-in-time compiler can (but i'd have check that).

c# optimization unity3d inlining

No comments:

Post a Comment