BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Enhancements for C2, the Compiler Behind VC++ and Native .NET

Enhancements for C2, the Compiler Behind VC++ and Native .NET

Bookmarks

Most developers don’t know much about C2, but it is a vital part of the Windows development lifecycle. It acts as the backend compiler for Visual C++, .NET natively compiled code, compiled T-SQL, and Objective-C on Windows.

Security in C++ is hard. The language is inherently unsafe when it comes to memory and it only takes one dangling pointer to create a major vulnerability. In order to mitigate the danger this poses, Microsoft introduced a new compiler switch called /Guard that changes the way virtual methods are called. This required major changes both the compiler, linker and operating system so it is only available on Windows 8.1 and higher.

Even though CPUs are more powerful year after year, that power isn’t being realized in terms of raw clock speed. So C++ needs to improve its support for resumable functions, a.k.a. co-routines. The cost of resume/suspend is equivalent to a normal function call, allowing for a zero overhead abstraction over existing async facilities

Control flow can now be vectorized, allowing C++ to speed up loops that contain simple if statements. Early benchmarks show improvements from 229 to 600% improvement in performance.

Normally performance improvements like this come with a substantial increase in build times. With whole application incremental compiling, the build times were actually decreased from a few percentage points to an order of magnitude. This is made possible by caching the ASTs that VC++ generates during the compilation process so that it can be fed back into the pipeline.

You can further improve the compilation speed by using /debug:fastlink to switch to the new PDB format. PDB generation, which is necessary for debugging, is often the most costly step in the build process. Under the new PDB format, the compiler generates and modifies lookup tables instead of regenerating the whole PDB each time.

.NET developers may be tempted to think all of this doesn’t matter to them, but under the Windows 10/Universal Apps model all .NET applications are natively compiled before they are delivered to the customer. This is done by piping the IL code into C2, the backend compiler for VC++.

C2 is also used to compile Objective-C for Windows. More on this topic, see our follow-up article, Compiling Objective-C into C++ with Visual Studio or watch the Channel 9 video Compiling Objective-C Using the Visual Studio 2015 C++ Code Generation that Builds Windows, SQL, .Net, and Office.

Rate this Article

Adoption
Style

BT