VB Migration Partner users may have found that migrated .NET application take several seconds to display their first form. This short article explains the cause for this performance degradation and how you can avoid it.
All .NET applications – regardless of the language they are written with or the fact that they have been migrated from VB6 by means of VB Migration Partner – are actually compiled in IL (Intermediate Language), which is a CPU-agnostic language that must be converted into Intel x86 or x64 opcodes before the application can actually run. The transformation from IL into actual CPU opcodes is performed by the JIT (Just-in-time) compiler, which is part of the .NET Framework environment.
In general, the JIT compiler – also known as “the JITter” – processes one method at a time, therefore the conversion usually occurs in the background and without a noticeable loss of performance. This is the usual case for business components that have no user interface.
For the JITter to convert a method, however, it is necessary that also all the classes/methods that that method uses or invokes are also JITted. This creates a performance penalty with Windows Forms application, because the very action of displaying a form with a few controls on it requires the JIT-compilation of a large portion of the System.Windows.Forms.dll assembly. The situation becomes a bit worse – but not remarkably worse – with projects that have been migrated from VB6, because also a portion of the CodeArchitects.VBLibrary.dll assembly needs to JIT-compiled before displaying the first form.
The solution to this performance problem can be found in the .NET Framework SDK, in the form of the NGEN tool. In addition to speeding up the startup phase, the NGEN tool can also help in reducing the memory footprint of an assembly, You can read more about the NGEN tool here.
In its simplest syntax, you just use NGEN with the install option, followed by the path of the .NET executable file that you want to optimize, as in this example:
NGEN install c:\myexes\myapp.exe
When running NGEN on a compiled .NET assembly generated by VB Migration Partner, you might see one or more of the following warnings:
Could not load file or assembly '<AssemblyName>, Version=…, Culture=neutral, PublicKeyToken=…' or one of its dependencies.
The system cannot find the file specified. while compiling method …
You can safely ignore this warnings, because they are related to assemblies referenced by the CodeArchitects.VBLibrary.dll assembly but not actually used by your migrated project. NGEN is able to correctly optimize your application even if you read these warnings.
You can easily avoid these warnings, though. Just copy the following DLLs from VB Migration Partner’s setup folder to the directory where the compiled .NET application resides:
INetCtlsObjects.dll, MSCommLib.dll, MSMAPI.dll, MSScriptControl.dll, RDO.dll