microsoft / dotnet

This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
https://devblogs.microsoft.com/dotnet/
MIT License
14.43k stars 2.21k forks source link

Why do .NET applications have at least a one-second startup delay? #1411

Open amymor opened 1 year ago

amymor commented 1 year ago

Hello I was seeking a language with the following parameters:

  1. Simple and readable syntax.
  2. Capability to effortlessly create Windows user interfaces.
  3. Native support for Windows applications.
  4. Superior performance and quick startup times.
  5. Portability, eliminating the need for extensive installations like the 10-20 GB Visual Studio IDE.
  6. It should already be widely used and possess a substantial community.

I discovered that VB6 meets my needs, but unfortunately, it is no longer supported. Therefore, I tried VB .NET. I found the transition to be quite easy, and the VB code was far more readable and concise compared to C#/C++. As I had mentioned, I did not want to install anything, so I did not try .NET 6 and 7. I aim to utilize built-in tools like vbc.exe or portable tools as much as possible. However, the problem with .NET framework is that the startup time remains consistently between 1-2 seconds, regardless of the code's weightiness or the language used (VB or C#). In contrast, VB6 applications start immediately. Here's an example that is written in VB .NET:

Imports System.Windows.Forms
Imports System.Drawing

Public Class Form1
    Inherits Form

    Private WithEvents button As New Button()
    Private WithEvents textBox As New TextBox()

    Public Sub New()
        button.Text = "Browse"
        button.Location = New Point(10, 10)
        Me.Controls.Add(button)

        textBox.Location = New Point(10, 40)
        Me.Controls.Add(textBox)
    End Sub
End Class

Module Module1
    Sub Main()
        Application.Run(New Form1)
    End Sub
End Module

What I did:

1.

CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319 
NGEN update
  1. I tried various options for the vbc.exe (and csc.exe) compilers, such as /optimize[+|-] and /platform.
  2. Different versions of the .NET framework (both 32-bit and 64-bit) including versions 2, 3.5, and 4.x.x.
  3. Using msbuild.exe to compile my application with the following command: msbuild /property:Configuration=Release;UseDotNetNativeToolchain=true MyFile.vbproj

here is content of MyFile.vbproj:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Sdk="Microsoft.NET.Sdk" >
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="DiCalc.vb" />
  </ItemGroup>

<Target Name="Build">
  <Vbc Sources="@(Compile)" OutputAssembly="DiCalc.exe" TargetType="WinExe"/>
</Target>

</Project>

Thanks in advance.