Why does braces take time on C# code?

307 views Asked by At

I am using Ants Performance Profiler 8.5 and when I saw the time each row of my code runs, I have noticed that the braces also take time.

Here is an image, you can see at the left of the braces the time in milliseconds:

enter image description here

Sometimes I get more time, like 5 ms...

Why is that? Is it the garbage collection?

1

There are 1 answers

0
Dominic Zukiewicz On BEST ANSWER

When a method is defined, the set of parameters that are in scope for the method are known by the compiler, called a maxstack. This hints at the amount of memory to allocate for the method.

This could be the source of the extra time - memory allocation by the CLR.

Adding more braces doesn't actually add more parameters to maxstack. Its scopes the whole method. Scope is more of a logical grouping, than being implemented by the CLR to release memory.

With your question on GC, I don't believe this is the root-cause of the problem. GC is ran by a separate thread when required. It could be the GC, but I seriously doubt it in your case.