Long initialization of the module catalog on a local machine

It was noticed that the first launch of the platform on a local machine takes quite a long time and initialization of the module catalog takes most of the time.

I found out that the source of long-term initialization of modules is the work of Windows defender. It checks the directories associated with the launch of the platform and thereby slows down the launch. He does not do this every launch, but only after some long interval between platform launches. The best way to detect this behavior is to launch the platform immediately after restarting Windows.


First, I added the directory with the modules to the exclusions. But it didn’t help. Then I added a directory with the source code of the modules, because I had a lot of symbolic links to them. That didn’t help either. Only the addition of the entire directory in which the platform is located had an effect and each launch, even after restarting Windows, began to run very quickly. I think the Windows defender checks all the files involved in the launch, including the platform itself.


To add directory to the exclusions on Windows 10:

  1. Press Win+X
  2. Select “System”
  3. Click " See details in Windows Security"
  4. Choose “Virus & threat protection”
  5. Click “Manage settings”
  6. Scroll screen and click “Add or remove exclusions” in Exclusions section
  7. Press the button “Add an exclusion” and select “Folder” in pop-up menu
  8. Specify the directory
1 Like

The alternative way for Windows 11 is to move the platform and source code of all modules to a Dev Drive.

Microsoft Defender Antivirus defaults to the new “performance mode” setting on Dev Drives, taking speed and performance into account, while providing a secure alternative to folder exclusions.

You can use the following PowerShell script to move package caches to your Dev Drive:

# Test-Driving Windows 11 Dev Drive for .NET
# https://blog.maartenballiauw.be/post/2023/11/22/test-driving-windows-11-dev-drive-for-dotnet.html

$DevDrive = "R:"
if (-not (Test-Path Packages)) {
    New-Item -Path $DevDrive\ -Name "Packages" -ItemType "directory"
}

# Move npm packages
Move-Item -Path $env:LocalAppData\npm-cache* -Destination $DevDrive\Packages

# Move NuGet packages
Move-Item -Path $env:UserProfile\.nuget* -Destination $DevDrive\Packages

# Set configuration
[Environment]::SetEnvironmentVariable("npm_config_cache", "$DevDrive\Packages\npm_cache", "User")
[Environment]::SetEnvironmentVariable("NUGET_PACKAGES", "$DevDrive\Packages\.nuget\packages", "User")