tagged [cil]
"nested if" versus "if and" performance using F#
"nested if" versus "if and" performance using F# The following code results in `slow1 = 1323 ms`, `slow2 = 1311 ms` and `fast = 897 ms`. How is that possible? Here: [Nested or not nested if-blocks?](h...
- Modified
- 23 May at 11:43
MS C# compiler and non-optimized code
MS C# compiler and non-optimized code The official C# compiler does some interesting things if you don't enable optimization. For example, a simple if statement: becomes something like the following i...
- Modified
- 7 Sep at 14:27
Where can I find a list of escaped characters in MSIL string constants?
Where can I find a list of escaped characters in MSIL string constants? I've written a program (in C#) that reads and manipulates MSIL programs that have been generated from C# programs. I had mistake...
Weird performance behavior
Weird performance behavior So I have this 2 methods which suppose to multiply a 1000 items long array of integers by 2. The first method: ``` [MethodImpl(MethodImplOptions.NoOptimization)] Power(int[]...
- Modified
- 26 Dec at 00:13
MethodImpl(NoOptimization) on this method, what does it do? And is it really nessecary?
MethodImpl(NoOptimization) on this method, what does it do? And is it really nessecary? Well, I wanted to hash a password, and i had a look at how ASP.net Identity does in the `Microsoft.AspNet.Identi...
- Modified
- 8 Dec at 01:20
What is the difference between ldc.i4.s and ldc.i4?
What is the difference between ldc.i4.s and ldc.i4? I was studying about the Intermediate Language for C#(IL) and came across the following piece of code:- ``` //Add.il //Add Two Numbers .assembly ex...
How can I implement StringBuilder and/or call String.FastAllocateString?
How can I implement StringBuilder and/or call String.FastAllocateString? I was curious to see if I could create an optimized version of `StringBuilder` (to take a stab at speeding it up a little, ). U...
- Modified
- 15 Nov at 14:23
Any real-world implications for general catch clause emitting System.Object as type filter?
Any real-world implications for general catch clause emitting System.Object as type filter? I recall hearing once that throwing an object of some type other than `System.Exception` (or those extending...
What is the purpose of the extra ldnull and tail. in F# implementation vs C#?
What is the purpose of the extra ldnull and tail. in F# implementation vs C#? The following C# function: compiles unsurprisingly to this: But the equivalent F# function: compiles to this: ``` IL_0000:...
- Modified
- 4 Mar at 15:48
What is the point of nop in CIL
What is the point of nop in CIL So I wrote the following code in C#. And the constructor of the class in IL looks like this ``` .method public hidebysig specialname rtspecialname instance void .ct...
Why does tail call optimization need an op code?
Why does tail call optimization need an op code? So [I've read many times before](https://stackoverflow.com/a/491463/5056) that technically .NET support tail call optimization (TCO) because it has the...
- Modified
- 23 May at 12:1
Why is IL.Emit method adding additional nop instructions?
Why is IL.Emit method adding additional nop instructions? I have this code that emits some `IL` instructions that calls `string.IndexOf` on a `null` object: ``` MethodBuilder methodBuilder = typeBuild...
- Modified
- 16 Sep at 00:41
Why does this (null || !TryParse) conditional result in "use of unassigned local variable"?
Why does this (null || !TryParse) conditional result in "use of unassigned local variable"? The following code results in : However, this code works fine (though, [ReSharper](http://en.wikipedia.org/w...
- Modified
- 31 Jan at 06:45
Compiler generated incorrect code for anonymous methods [MS BUG FIXED]
Compiler generated incorrect code for anonymous methods [MS BUG FIXED] See the following code: ``` public abstract class Base { public virtual void Foo() where T : class { Console.WriteLine("b...
- Modified
- 21 Feb at 17:49
Does setting the platform when compiling a c# application make any difference?
Does setting the platform when compiling a c# application make any difference? In VS2012 (and previous versions...), you can specify the target platform when building a project. My understanding, thou...
- Modified
- 8 Oct at 19:25
What is the Implementation of Generics for the NET Common Language Runtime
What is the Implementation of Generics for the NET Common Language Runtime When you use generic collections in C# (or .NET in general), does the compiler basically do the leg-work developers used to h...
Why does the type System.__ComObject claim (sometimes) to be public when it is not?
Why does the type System.__ComObject claim (sometimes) to be public when it is not? Just an oddity I happened to discover when I was reflecting over all types to check something else out of curiosity....
- Modified
- 6 Aug at 21:1
Why are static classes considered “classes” and “reference types”?
Why are static classes considered “classes” and “reference types”? I’ve been pondering about the C# and CIL type system today and I’ve started to wonder why static classes are considered classes. Ther...
Why does this very simple C# method produce such illogical CIL code?
Why does this very simple C# method produce such illogical CIL code? I've been digging into IL recently, and I noticed some odd behavior of the C# compiler. The following method is a very simple and v...
C# compiler doesn’t optimize unnecessary casts
C# compiler doesn’t optimize unnecessary casts A few days back, while writing an answer for [this question](https://stackoverflow.com/questions/2208315/why-is-any-slower-than-contains) here on overflo...
- Modified
- 23 Sep at 14:34
Iterator block generates try-fault in IL
Iterator block generates try-fault in IL After experimenting with an iterator block I noticed the generated IL code is not what I expect it to be. Instead of a try-finally block a try-fault block is g...
Is there a difference between `x is int?` and `x is int` in C#?
Is there a difference between `x is int?` and `x is int` in C#? The two methods above seems to behave equally, both when passing `null` reference or boxed `T` value. However, the generated MSIL code i...
What is the first argument in a parameterless constructor?
What is the first argument in a parameterless constructor? I have simple program like this: I d
- Modified
- 8 Feb at 11:20
Behavior of F# "unmanaged" type constraint
Behavior of F# "unmanaged" type constraint F# supports a type constraint for "unmanaged". This is not the same as a value type constraint like "struct" constraints. [MSDN notes](http://msdn.microsoft....
How do i prevent my code from being stolen?
How do i prevent my code from being stolen? What happens exactly when I launch a .NET exe? I know that C# is compiled to IL code and I think the generated exe file just a launcher that starts the runt...
- Modified
- 26 Feb at 14:33