상세 컨텐츠

본문 제목

Tips for Performance Improvement - Visual Studio

본문

A lot of developers use Visual Studio as their IDE.  I also have used since version 2005 through 2022.  However, you sometimes see freezing or slowing down while debugging or even during writing lines and lines of codes.  Whenever I install a new version of Visual Studio, I use the following methods to keep the Visual Studio perform as expected.  Many of tools and options in Visual Studio are for developer's convenience, but you must balance the convenience and the price you pay for the convenience. 
 

반응형

Please keep in mind that this article is NOT for Visual Studio Code.  It is for Visual Studio Community, Professional and Enterprise even though there may be some similarities.  I have never used VS Code so I cannot say 100% that these will work.
 

728x90

1. CodeLens 

It is for Professional and Enterprise. It can find all method references in the project but it will degrade performance of your IDE as it consumes a lot of memory. 
 
You can disable this option by going to Tools > Options > Text Editor > All Languages > CodeLens


2. XAML Designer 

XAML Designer is a convenience tool for developing WPF, UWP, Xamarin.Forms, or MAUI Apps.  It resembles the design tool for WinForm apps.  It is useful for entry XAML developers because you can easily visualize the XAML code during design time. However, it consumes high CPU and memory.  If you are familiar with XAML, it is better to disable this option.  

You can disable this option by going to Tools > Options > XAML Designer > Enable XAML Designer


3. Map Mode

Map Mode is a long and narrow window on the right hand side of your coding window.  It is useful to see where the code error is and last edited code section was.  You can also instantly move anywhere in the code window by pressing CONTROL key and a mouse click to the location.  I love this tool but when your computer is not powerful enough, you will see a performance hit on IDE.

You can disable this option by going to Tools > Options > Text Editor > All Languages > Use map mode in Scroll Bars section


4. Windows Defender or ANY Anti-Virus App

Last but NOT the least.  This is probably the most important part.  Any anti-virus scan apps will scan running processes in real-time.  When you are in IDE, whether running debug or coding, you are running many different processes.  These are constantly scanned by these apps.  So you will see performance hit by the scanners.  It is highly recommended to exclude the processes that Visual Studio in the anti-virus apps, INCLUDING ALL of your projects folders and VS  installation folders.
 
The PowerShell code below will automatically exclude necessary folders in Windows Defender app.  If you have other anti-virus apps, you must exclude them manually.  Copy and paste the code below and save the file with .ps1 extension so that you can run in PowerShell window.  When you run this code, you will have to enter the location of your VS projects.  

$userPath = $env:USERPROFILE
$pathExclusions = New-Object System.Collections.ArrayList
$processExclusions = New-Object System.Collections.ArrayList

$pathExclusions.Add('C:\Windows\Microsoft.NET') > $null
$pathExclusions.Add('C:\Windows\assembly') > $null

$pathExclusions.Add($userPath + '\Downloads\HeidiSQL_11.3_64_Portable') > $null

$pathExclusions.Add($userPath + '\.dotnet') > $null
$pathExclusions.Add($userPath + '\.librarymanager') > $null

$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VisualStudio') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VisualStudio Services') > $null
$pathExclusions.Add($userPath + '\AppData\Local\GitCredentialManager') > $null
$pathExclusions.Add($userPath + '\AppData\Local\GitHubVisualStudio') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\dotnet') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VSApplicationInsights') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VSCommon') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Temp\VSFeedbackIntelliCodeLogs') > $null

$pathExclusions.Add($userPath + '\AppData\Roaming\Microsoft\VisualStudio') > $null
$pathExclusions.Add($userPath + '\AppData\Roaming\NuGet') > $null
$pathExclusions.Add($userPath + '\AppData\Roaming\Visual Studio Setup') > $null
$pathExclusions.Add($userPath + '\AppData\Roaming\vstelemetry') > $null
$pathExclusions.Add($userPath + '\AppData\Roaming\HeidiSQL') > $null

$pathExclusions.Add('C:\ProgramData\Microsoft\VisualStudio') > $null
$pathExclusions.Add('C:\ProgramData\Microsoft\NetFramework') > $null
$pathExclusions.Add('C:\ProgramData\Microsoft Visual Studio') > $null
$pathExclusions.Add('C:\ProgramData\MySQL') > $null

$pathExclusions.Add('C:\Program Files\Microsoft Visual Studio') > $null
$pathExclusions.Add('C:\Program Files\dotnet') > $null
$pathExclusions.Add('C:\Program Files\Microsoft SDKs') > $null
$pathExclusions.Add('C:\Program Files\Microsoft SQL Server') > $null
$pathExclusions.Add('C:\Program Files\MySQL') > $null
$pathExclusions.Add('C:\Program Files\IIS') > $null
$pathExclusions.Add('C:\Program Files\IIS Express') > $null

$pathExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio') > $null
$pathExclusions.Add('C:\Program Files (x86)\dotnet') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft SDKs') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft SQL Server') > $null
$pathExclusions.Add('C:\Program Files (x86)\IIS') > $null
$pathExclusions.Add('C:\Program Files (x86)\IIS Express') > $null

$processExclusions.Add('ServiceHub.SettingsHost.exe') > $null
$processExclusions.Add('ServiceHub.IdentityHost.exe') > $null
$processExclusions.Add('ServiceHub.VSDetouredHost.exe') > $null
$processExclusions.Add('ServiceHub.Host.CLR.x86.exe') > $null
$processExclusions.Add('Microsoft.ServiceHub.Controller.exe') > $null
$processExclusions.Add('PerfWatson2.exe') > $null
$processExclusions.Add('sqlwriter.exe') > $null

Write-Host "This script will exclude all folders and processes of Visual Studio 2022 in Windows Defender."
Write-Host ""
$projectsFolder = Read-Host 'Please enter your Visual Project folder location: (e.g.: c:\source)'

Write-Host ""
Write-Host "Adding Path Exclusion: " $projectsFolder
Add-MpPreference -ExclusionPath $projectsFolder

foreach ($exclusion in $pathExclusions) 
{
    Write-Host "Adding Path Exclusion: " $exclusion
    Add-MpPreference -ExclusionPath $exclusion
}

foreach ($exclusion in $processExclusions)
{
    Write-Host "Adding Process Exclusion: " $exclusion
    Add-MpPreference -ExclusionProcess $exclusion
}

Write-Host ""
Write-Host "These are the excluded items:"

$prefs = Get-MpPreference
$prefs.ExclusionPath
$prefs.ExclusionProcess

Write-Host ""
Write-Host "Have fun coding!"
Write-Host ""

How to run .ps1 script in PowerShell or Command Prompt:


Using PowerShell
1. Open PowerShell as Administrator
2. You will see PS C:...> in the left (see screenshot below).

PowerShell Screen

3.  Using cd command, go to the folder where the ps1 file is located
4.  Enter the name of the script as below (be careful with the syntax) and press Enter.  

.\name-of-the-script.ps1 (press Enter after)


Using Command Prompt
Use the following line of command (be careful with the syntax, number of double quotes)

powershell -noexit "& ""full-path-of-the-script\name-of-the-script.ps1""" (press Enter)

 

728x90
반응형

관련글 더보기