Partager via


JIT Optimization and Debugging

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

When you debug a managed application, Visual Studio suppresses optimization of just-in-time (JIT) code by default. Suppressing JIT optimization means you are debugging non-optimized code. The code runs a bit slower because it is not optimized, but your debugging experience is much more thorough. Debugging optimized code is harder and recommended only if you encounter a bug that occurs in optimized code but cannot be reproduced in the non-optimized version.

JIT optimization is controlled in Visual Studio by the Suppress JIT optimization on module load option. You can find this option on the General page under the Debugging node in the Options dialog box.

If you clear the Suppress JIT optimization on module load option, you can debug optimized JIT code, but your ability to debug may be limited because the optimized code does not match the source code. As a result, debugger windows such as the Locals and Autos window may not display as much information as they would if you were debugging non-optimized code.

Another important difference concerns debugging with Just My Code. If you are debugging with Just My Code, the debugger considers optimized code to be non-user code, which should not be displayed while you are debugging. Consequently, if you are debugging JIT optimized code, you probably want to turn Just My Code off. For more information, see Restrict stepping to Just My Code.

Remember that the Suppress JIT optimization on module load option suppresses optimization of code when modules are loaded. If you attach to a process that is already running, it may contain code that is already loaded, JIT-compiled, and optimized. The Suppress JIT optimization on module load option has no effect on such code, although it will affect modules that are loaded after you attach. In addition, the Suppress JIT optimization on module load option does not affect modules, such as WinForms.dll, that are created with NGEN.

See Also

Debugging Managed Code
Navigating through Code with the Debugger
Attach to Running Processes
Managed Execution Process