How to compile .NET application for CPU optimization?

I have a .NET C # application that should only run on one computer with a known configuration (HP DL120 G7, Xeon E3-1220, Windows Server 2008 R2 Foundation, if that matters). I do not need to run this application on other computers.

I want to:

  • do it as quickly as possible (maybe compile with the Xeon E3-1220 key or something like that)
  • Little (It should not be trivial to restore C # source code from binary files).

Do I have to somehow compile my own windows code? Perhaps I should use some special compiler options?

+4
source share
3 answers

You can compile it in Release mode to enable optimization. Alternatively, you can run ngen.exe to generate your own DLL files that will not carry the JIT overhead.

However, keep in mind that all of these measures and tools are not a silver bullet for poorly written code (not to mention what you have). You should profile your application and see if you can improvise the execution time of any code, as well as learn slower paths (and strive to improve them).

To protect it, use a good obfuscator such as (Salamander, SmartAssembly, etc.). It will not be completely indistinguishable, but it will make it much more difficult.

To absolutely protect it, enter the code in C ++! You can compile it with the /clr option, which will make them immune to reflection and disassembly.

+4
source

Easily recover code from .Net assemblies. You can go some way by messing up the content (for this google).

As for compilation, the CLR will compile it efficiently when the process starts - you don’t have to worry about that. If the startup time is high, you can use ngen (AOT compiler) to compile the assembly:

http://en.wikipedia.org/wiki/Native_Image_Generator

If you want to make sure that it is fast, make sure that you are compiled in release mode, but with optimization (this will be in your project properties).

+2
source

You can use ngen to create and cache optimized native images of your assemblies.

+1
source

All Articles