.NET

System.Diagnostics.StackFrame performance degrade in Windows 10

System.Diagnostics.StackFrame performance degrade in Windows 10

If after you upgrade to Windows 10 or .NET Framework 4.7.1, and you notice a significant decrease in performance when you run .NET Framework applications that use the System.Diagnostics.StackFrame class, then this post might interest you. We will look at the cause, and then offer known fixes for the error.

System.Diagnostics.StackFrame performance degrade

An application that had acceptable performance running on the .NET Framework 4.7 or earlier versions executes more slowly when running on the .NET Framework 4.7.1. Applications typically rely on StackFrame when they throw .NET exceptions. If this occurs at a high rate (more than 10 incidents per second), applications can slow down significantly (tenfold) and run noticeably slower than before.

Cause of the System.Diagnostics.StackFrame performance degrade

The .NET Framework 4.7.1 in Windows 10 added support for detecting and parsing the Portable PDB file format to show file and line number information in stack traces. As part of this change, each function in a stack trace has its defining module checked to determine if that module uses the Portable PDB format. Due to some differences in the internal caching policy, the runtime spends far more time searching for Portable PDBs than previous .NET Framework versions spent searching for classic Windows PDBs.

This causes formatted stack traces to be produced more slowly than before.

This issue does not change the number of exceptions that are thrown. However, it does significantly decrease the ability of applications to handle those exceptions.

Applications that use IKVM library are known to be affected by this issue if they probe for assemblies. Probing for assemblies is known to cause exceptions.

Fix System.Diagnostics.StackFrame performance degrade issue

To resolve this issue, Microsoft recommends using either of the following methods.

1] Use a different constructor for StackFrame that takes a Boolean argument

This is the preferred solution.

If application developers are able to make changes to their applications, call the System.Diagnostics.StackTrace.#ctor(Boolean) constructor by using a false argument to avoid capturing source information. This avoids the section of the code in which performance is decreased.

2]  Rollback or upgrade to the latest Windows 10 version

In this method, roll back to the previous version/build or upgrade to the latest version/build of Windows 10 if you're experiencing this issue and you're not currently running the latest version of Windows 10. Also uninstall .NET Framework 4.7.1 if present, from your computer and then download and install a previous version or the latest version of .NET Framework.

Hope this helps!

Battle for Wesnoth Tutorial
The Battle for Wesnoth is one of the most popular open source strategy games that you can play at this time. Not only has this game been in developmen...
0 A.D. Tutorial
Out of the many strategy games out there, 0 A.D. manages to stand out as a comprehensive title and a very deep, tactical game despite being open sourc...
Unity3D Tutorial
Introduction to Unity 3D Unity 3D is a powerful game development engine. It is cross platform that is it allows you to create games for mobile, web, d...