Modern Source Code Size and Internal Consistency

Work continues on Modern C++ for the Windows Runtime as I have time to spare. I recently replaced enumerator values with literals to save over 200KB in the resulting library. Previously, I played it safe and simply used the underlying ABI for enumerator values:

enum class ApplicationExecutionState
{
    NotRunning = ABI::Windows::ApplicationModel::Activation::ApplicationExecutionState_NotRunning,
    Running = ABI::Windows::ApplicationModel::Activation::ApplicationExecutionState_Running,
    Suspended = ABI::Windows::ApplicationModel::Activation::ApplicationExecutionState_Suspended,
    Terminated = ABI::Windows::ApplicationModel::Activation::ApplicationExecutionState_Terminated,
    ClosedByUser = ABI::Windows::ApplicationModel::Activation::ApplicationExecutionState_ClosedByUser,
};

The Modern compiler now simply generates enumerations as follows:

enum class ApplicationExecutionState
{
    NotRunning = 0,
    Running = 1,
    Suspended = 2,
    Terminated = 3,
    ClosedByUser = 4,
};

Apart from the dramatic reduction in code size, it also benefits compile times, reduces the work required by the struggling IntelliSense compiler, and generates smaller precompiled and IntelliSense databases.

I then added an optional -debug command line option to add static_assert consistency checks, adding over 3,000 compile-time assertions. Of course, this goes beyond simply checking enumerator values. It’s not something you’ll want to enable all of the time. Instead, it’s a handy way to quickly verify whether the language projection for a new version of the Windows SDK (e.g. Windows 10) is internally consistent with the underlying ABIs.

One thought on “Modern Source Code Size and Internal Consistency

  1. Jeff

    Great idea. I will certainly borrow your idea (moving several static_asserts to conditional compilation). Thanks for the note.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s