Build Code Faster
Another improvement for developing C++ code that targets the CLR is that incremental builds are significantly faster. One sore point in the development of large CLR applications that have C++ components has traditionally been the need to rebuild dependencies, even when the core components have had only implementation changes and no interface changes. This was due to CLR assemblies packaging both the metadata and the implementation of a component in one binary. As a result, large C++ projects that depend on CLR assemblies would need to be rebuilt if any part of that CLR assembly changed.
The upcoming release of Visual Studio adds a new tool that creates a metadata-only assembly that captures the interface and only rebuilds dependent C++ projects when the interface assembly has changed. Changes to the implementation of an assembly do not trigger a rebuild of dependent assemblies. This can significantly reduce build times in the incremental build scenario, subsequently improving developer productivity.
While I’m on the topic of build throughput, one of my favorite features of Visual Studio "Orcas" is its ability to compile source files in parallel. This works for both native and managed code. CL.EXE provides a new switch, /MP, to enable this behavior. The syntax for the new switch is as follows:
/MP[n] use up to ‘n’ processes for compilation
Here, n essentially specifies the number of processors to be used. When the number of processors is not specified, the compiler uses the number of logical processors available on the machine. When a number is specified, exactly n processes are spawned for compilation.
The parallel compilation feature works by compiling different translation units in different processes; a single translation unit cannot be compiled across multiple processes. For example, consider the results of the following compiler invocation when run on a quad-processor machine:
CL /c /MP a.cpp b.cpp c.cpp d.cpp e.cpp f.cpp
The compiler will end up compiling four translation units in parallel with new translation units being compiled as soon as one of the four processors is freed up.
Now consider the results of the following compiler invocation run on a dual-processor machine:
CL /c /MP a.cpp
The compiler will perform a serial compilation of the single translation unit that it received since it does not perform parallel compilation within a translation unit.