Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Elemar Júnior
Elemar Júnior

Posted on • Originally published atelemarjr.com on

     

Is the Managed Code Slower than the Native Code?

That is a question that I have been answering for years.The answer is an emphatic “NO” in most cases.

What is true is that .NET make it very easy to write slow code.Being more friendly, it is pretty standard for .NET developers being sloppy and uncritical about performance and that, I think, is the main reason why some .NET applications performance sucks.

RavenDB team is doing a great job proving, again and again, that managed code can be so fast as Native Code. Why? Because we pay attention to performance starting from thearchitecture to theimplementation.

When you build your .NET code, the compiler translates it to Intermediate Language and metadata. Then, when you run your code, whenever a method is executed for the first time, the Just in Time Compiler convert it to assembly code. Most of the code optimization happens at this stage (If you want to understand this process, I recommend you toread this post).

The quality of the JITted code is fantastic. Microsoft has improved the JIT, especially quite recently.

In fact, there are advantages in the Managed World:

  1. Since the code is JITted as it is executed, its location in memory is better than that of native code. The related code will be often closer, commonly in a single memory page or the cache. So we have fewer page faults;
  2. Different from Native Code, .NET applications are less susceptible to memory fragmentation and. When it happens, the Garbage Collection compacts the heap solving the problem.
  3. The memory allocation occurs with no contention.

Remember: Garbage Collection in .NET is deterministic. We can significantly affect how often it runs by controlling the memory allocation patterns, object scope, etc.

Is the Managed Code Slower than the Native Code? appeared first atElemar JR.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I work in organizations, helping programmers, architects, and executives develop software that meets business needs.
  • Location
    Campo Bom, Brazil
  • Joined

More fromElemar Júnior

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp