Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slowness on first run of a self-contained WinForms exe #37063

Closed
snickler opened this issue May 27, 2020 · 4 comments
Closed

Slowness on first run of a self-contained WinForms exe #37063

snickler opened this issue May 27, 2020 · 4 comments
Labels
area-Single-File tenet-performance Performance related issue untriaged New issue has not been triaged by the area owner

Comments

@snickler
Copy link
Contributor

Description

The first run of a self-packaged WinForms exe results in 5 second delay before the form window presents itself to the screen. Initially I was filing this solely based on running .NET 5 Preview 6 on ARM64, but this also affects .NET Core the 3.1.3 SDK on x64.

On x64

mkdir winformsx64 && cd winformsx64 && dotnet new winforms
dotnet publish -r win-x64 /p:PublishSingleFile=true
cd bin\Debug\netcoreapp3.1\win-x64\publish
winformsx64.exe

On ARM64

mkdir winformsarm64 && cd winformsarm64 && dotnet new winforms
dotnet publish -r win-arm64 /p:PublishSingleFile=true
cd bin\Debug\net5.0\win-arm64\publish
winformsarm64.exe

Running both of these on their individual supported platforms will result in at least a 5 second delay before the form displays.

This behavior seems to also be impacted when extra NuGet packages are added. I tested this by throwing Microsoft.PowerShell.SDK version 7.0.1 into the projects: dotnet add package Microsoft.PowerShell.SDK, clearing the bin folder and then republishing the executable. I noticed the first run time jump from 5 seconds to around 12-15 seconds.

Configuration

x64

OS: Windows 10 19631.1
SDK: .NET Core SDK 3.1.300
Host: 3.1.4

ARM64

OS: Windows 10 19631.1
SDK: .NET SDK 5.0.100-preview.6.20276.4
Host: 5.0.0-preview.6.20271.10

Regression?

Data

I had no easy way of tracking the timing from when I pressed enter on the keyboard and when the form appeared, so I used Process Explorer to look at the timing of certain threads. The time lined up with my counting.

Barebones WinForms App first loading

image

When Form was presented to the screen

image

Barebones WinForms App with Microsoft.PowerShell.SDK NuGet package - first loading

image

When Form was presented to the screen

image

Analysis

The self-published executables extract the bundled framework to %LOCALAPPDATA%\Temp\.net\{nameofexe}\{somehashofcharacters}\ on first run, or rebuilding with changes. Subsequent runs load fast, since it reads the dlls from the temp directory. Deleting the directory will cause those framework files to be re-extracted and will re-create the directory along with the delay experienced on a first run. This process seems to be directly involved with contributing to the slow loading times.

image

image

@snickler snickler added the tenet-performance Performance related issue label May 27, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label May 27, 2020
@ghost
Copy link

ghost commented May 27, 2020

Tagging subscribers to this area: @swaroop-sridhar
Notify danmosemsft if you want to be subscribed.

@snickler
Copy link
Contributor Author

Linking to #36590

@swaroop-sridhar
Copy link
Contributor

@snickler single-file apps currently execute by self-extracting the bundled contents to a temp-folder on first-run as explained in this document. The extracted files are reused on subsequent runs, this improving the startup times. The first run is also slowed down by antivirus checks. So, the slowness on first run is expected.

In .net 5 (upcoming previews), managed DLLs will be processed directly from the bundle without need for extraction (please see #32822) which will help ameliorate the problem.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Single-File tenet-performance Performance related issue untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

4 participants