C#和编译器优化器。 [英] C# and compiler optimizer.
问题描述
我正在尝试理解由C#创建的IL汇编程序,但据我所知,
看,C#编译器没有进行优化。
优化是由JIT完成,但它只能到目前为止。
在C ++中,您可以为属性和方法添加''inline''关键字
可以插入到生成的代码中,这样你就可以避免调用,从而避免了开销,但据我所知,C#似乎没有这个
的功能。
或者是因为我使用的是VC#2003标准版,这个优化是什么?b $ b未完成?
我试图理解由C#创建的IL汇编程序,但据我所知,C#编译器没有进行优化。
优化由JIT完成,但它只能到目前为止。
如果使用
/ o +进行编译,C#编译器会自行进行一些优化,但是大多数都是由JIT编译器完成的。
在C ++中你可以把''inline''关键字
编译器可以随意忽略它。
但据我所知,C#似乎没有这个功能。
对,但是JIT编译器会内联一些方法调用。
或者是因为我使用的是VC#2003标准版本优化是否未完成?
No.
Mattias
-
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请回复到新闻组。
Olaf Baeyens写道:
我试图理解由C#创建的IL汇编程序,但是至于我可以看到,C#编译器没有进行优化。
优化是由JIT完成的,但它只能到目前为止。
< theory>
JIT可以从传统编译器运行优化开始,即
。离线编译器永远不会更优化。比JIT。
< / theory>
在C ++中,您可以为可以插入的属性和方法添加''inline''关键字。生成代码,这样你就可以避免调用,从而避免了开销,但据我所知,C#似乎没有这个功能。
即使在C ++中,内联也是如此。是一个链接说明符,而不是
inling的规范。 c ++编译器可以选择将其作为单独的函数发出
和调用指令,但该函数必须具有内部链接。
您可以轻松验证这一点通过编译递归函数:
inline int f(int x){return f(x + 1); }
int main(int argc,string ** argv){return f(0); }
编译器(以及一些JIT')今天对*
内联应该应用什么时候应该进行非常*高级分析。 br />
你有哪些具体的性能问题可以通过
来解决,让你指定内联?
-
Helge Jensen
mailto:他********** @ slog.dk
sip:他**** ******@slog.dk
- =>塞巴斯蒂安的封面音乐: http://ungdomshus.nu < = -
> >我正在尝试理解由C#创建的IL汇编程序,但就我而言,
可以看,没有优化完成通过C#编译器。
优化由JIT完成,但它只能到目前为止。
如果用
/ o +,但你说得对,大部分都是由JIT编译器完成的。
在C ++中你可以把''inline''关键字
编译器可以自由地忽略它。
在很多情况下,C ++编译器没有内联这部分如果我
看看我的代码。
但据我所知,C#似乎没有这个
功能。
对,但是JIT编译器会内联一些方法调用。
我没注意到这之前,但它会很好。 :-)
I am trying to understand the IL assembler created by C# but as far as I can
see, there is no optimizing done by the C# compiler.
Optimizing is done by the JIT, but it can only go so far.
In C++ you can put the ''inline'' keyword for properties and methods that
could be inserted into the generated code so you avoid a call and thus the
overhead, but as far as I can see, C# does not seem to have this
functionality.
Or is it because I use the VC# 2003 standard edition that this optimizing is
not done?
I am trying to understand the IL assembler created by C# but as far as I can
see, there is no optimizing done by the C# compiler.
Optimizing is done by the JIT, but it can only go so far.
The C# compiler does some optimizations itself if you compile with
/o+, but you''re right that most of it is done by the JIT compiler.
In C++ you can put the ''inline'' keyword
And the compiler is free to ignore it.
but as far as I can see, C# does not seem to have this
functionality.
Right, but the JIT compiler will inline some method calls.
Or is it because I use the VC# 2003 standard edition that this optimizing is
not done?
No.
Mattias
--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Olaf Baeyens wrote:
I am trying to understand the IL assembler created by C# but as far as I can
see, there is no optimizing done by the C# compiler.
Optimizing is done by the JIT, but it can only go so far.
<theory>
A JIT can just start by running the optimizations a traditional compiler
would do. Offline compilers can never be more "optimizing" than JIT.
</theory>
In C++ you can put the ''inline'' keyword for properties and methods that
could be inserted into the generated code so you avoid a call and thus the
overhead, but as far as I can see, C# does not seem to have this
functionality.
Even in C++, "inline" is a linkage-specifier, not a specification of
inling. The c++ compiler can choose to emit it as a separate function
and call-instructions, but the function must have internal linkage.
You can easily verify this by compiling a recursive function:
inline int f(int x) { return f(x+1); }
int main(int argc, string** argv) { return f(0); }
Compilers (and some JIT''s) today have *very* advanced analysis of when
inlining should be applied and when it should not.
Which specific performance problem do you have which can be solved by
letting you specify inlining?
--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
> >I am trying to understand the IL assembler created by C# but as far as I
cansee, there is no optimizing done by the C# compiler.
Optimizing is done by the JIT, but it can only go so far.
The C# compiler does some optimizations itself if you compile with
/o+, but you''re right that most of it is done by the JIT compiler.In C++ you can put the ''inline'' keyword
And the compiler is free to ignore it.
True in a lot of cases, the C++ compiler just doesn''t inline this part if I
look at my code.
but as far as I can see, C# does not seem to have this
functionality.
Right, but the JIT compiler will inline some method calls.
I did not notice this before, but it would be nice. :-)
这篇关于C#和编译器优化器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!