none
System.ComponentModel subclass instantiation very slow when optimize is enabled in a .net 4.0 x64 VB project RRS feed

  • Question

  • Hi,

    Our company is facing a crucial performance issue with component instantiation (using Component Model). We currently use .net 3.5 for most of our products and we cannot migrate to .net 4.0/4.5 because of that performance issue. The problem only occurs when the component loads for the first time and in the following commonly used conditions:
    - Optimization is enabled
    - Component is in VB.NET
    - Target framework is .net 4.0 or later
    - Solution platform is x64

    If the component contains a lot of subcomponents, the creation of the instance of the class takes several seconds. In our case, the class contains 300 child components and takes 53 seconds to be instantiated with the above conditions. If we change one of the above conditions, the performance issue disappears. Moreover, we have noticed a huge memory and CPU usage during that time.

    We have attached a sample project (VB.NET console application) with a basic UserControl with several sub components. The application creates 4 instances of the UserControl in a row and displays the elapsed time between each new instance. In regular cases, the first instance takes 80/200ms to be created. However, with the above conditions, the first instance takes almost 4s to be created. That’s 50/20 times slower. Even with a basic configuration, we noticed that enabling optimizations increase load time by 5 (60ms to 300ms).
    From what we saw and analyzed, it seems to be a JIT compiler issue.

    Download sample project: https://dl.dropboxusercontent.com/u/20096697/msdn_vb_new_component_issue.zip

    Please note that the issue is not present while debugging the application within Visual Studio or using any profiler other than “sampling” mode.

    We are currently running on Windows 7 x64 with .net 4.5 and Visual Studio 2012 installed.

    Does anyone have any information about this behavior?

    Thanks a lot.

    Friday, July 26, 2013 2:52 PM

Answers

  • Hi  Sebastien,

    It looks like this is the current behavior of JIT . How ever for quicker runs please try one of the below . 

    1. Reduce the number of controls on the form, and try to have more functions and initialize controls

    2. Disable the optimization .

    3. Alternatively please add the following line inside the InitializeComponent function, just before the #region Windows Form…..

    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoOptimization)]

     
    If you still have the issue and want to investigate this further , please open a support ticket with us .



    Tuesday, August 27, 2013 6:29 PM
  • Hi ,

    Thank you for your reply.

    To your issue, we have submitted to related department to handle further, Once it has the result we will reply to you as soon as possible, please wait patiently .

    Thanks  for your cooperation, have a nice day.

    Best Regards,

    Monday, August 5, 2013 2:59 AM

All replies

  •  

    Hello,

    Welcome to MSDN Forum.

    From your description, I think you can try to update to the latest .net framework  and all patches are installed on .net framework 4.0.if it's not ok. you can offer more information in detail,such as:

     1)Windows 7 specific version include which patches are installed;

    2)Visual Studio 2012 specific version 

    3).NET Framework specific version  

    4) Specific compiler configuration ,especially Open after optimizing compiler options included in the project configuration. 

    Hopes these help, if you have any question, please feel free to let me know.

    Best Regards,

     


    Lilia Gong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Monday, July 29, 2013 11:49 PM
    Moderator
  • Hello,

    Thanks for your reply.

    We already have the latest version of the .Net framework installed on both our developers laptops and our web servers.

    Web Server:

     1) Windows Server 2008 R2 Standard x64 (6.1.7601) with the following installed patches: https://dl.dropboxusercontent.com/u/20096697/patches_winserver2008r2_web.txt

     2) None

     3) .NET Framework version 4.5.50709

     4) N/A

    Developer PC:

     1) Windows 7 Enterprise x64 SP1 (6.1.7601) with the following installed patches: https://dl.dropboxusercontent.com/u/20096697/patches_win7x64_dev.txt

     2) Visual Studio 2012 version 11.0.60610.01 Update 3

     3) .NET framework version 4.5.50709

     4) Compiler configurations:

    Target CPU: x64

    Target Framework: 4.0

    Remove integer overflow checks: NO

    Enable optimizations: YES

    DLL base address: &H00400000 (cannot be changed)

    Generate debug info: pdb-only

    Define DEBUG constant: NO

    Define TRACE constant: YES

    Custom constants: N/A

    Generate serialization assemblies: AUTO

    VB Compiler command line arguments from Visual Studio if needed:

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Vbc.exe
    /noconfig
    /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Diagnostics,System.Linq,System.Xml.Linq
    /optioncompare:Binary
    /optionexplicit+
    /optionstrict:custom
    /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
    /optioninfer+
    /nostdlib
    /platform:x64
    /rootnamespace:msdn_vb_new_component_issue
    /sdkpath:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
    /highentropyva-
    /doc:obj\x64\Release\msdn_vb_new_component_issue.xml
    /define:"CONFIG=\"Release\",TRACE=-1,_MyType=\"Console\",PLATFORM=\"x64\""
    /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.DataSetExtensions.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Deployment.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Drawing.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Windows.Forms.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.Linq.dll"
    /main:msdn_vb_new_component_issue.Module1
    /debug:pdbonly
    /filealign:512
    /optimize+
    /out:obj\x64\Release\msdn_vb_new_component_issue.exe
    /resource:obj\x64\Release\msdn_vb_new_component_issue.Resources.resources
    /resource:obj\x64\Release\msdn_vb_new_component_issue.UserControl1.resources
    /target:exe
    Module1.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb" UserControl1.Designer.vb UserControl1.vb "C:\Users\scado\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.vb"

    If you need more information, please let me know. Thanks a lot.

    Best regards,

    Wednesday, July 31, 2013 8:32 AM
  • Hi ,

    Thank you for your reply.

    To your issue, we have submitted to related department to handle further, Once it has the result we will reply to you as soon as possible, please wait patiently .

    Thanks  for your cooperation, have a nice day.

    Best Regards,

    Monday, August 5, 2013 2:59 AM
  • Hi,

    Thanks for your answer. I will wait for your reply.

    Have a nice day.

    Best regards,

    Thursday, August 8, 2013 1:52 PM
  • Hi  Sebastien,

    It looks like this is the current behavior of JIT . How ever for quicker runs please try one of the below . 

    1. Reduce the number of controls on the form, and try to have more functions and initialize controls

    2. Disable the optimization .

    3. Alternatively please add the following line inside the InitializeComponent function, just before the #region Windows Form…..

    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoOptimization)]

     
    If you still have the issue and want to investigate this further , please open a support ticket with us .



    Tuesday, August 27, 2013 6:29 PM
  • Hi Nandeesh,

    Thanks for your reply. We will investigate the 3rd point further.

    Best regards,

    Wednesday, August 28, 2013 8:01 AM