Skip to content

MCCF: Make the Common Case Fast

amirroth edited this page Sep 20, 2021 · 3 revisions

One of the mantras of high-performance programming is "Make the Common Case Fast" or for short MCCF. Like pretty much every other program, EnergyPlus has a core set of features that are used in pretty much every model and others that are used much less frequently. The idea behind MCCF is to remove the handling of rarely-used features from the main loops of the code to help keep those the handling of commonly used features tight and highly optimized.

Even checking for the existence of a rarely-used feature takes time. If the feature is not used during the particular run, the branch associated with the check will be correctly predicted and will not result in a dynamic penalty (see this page to learn about data-dependent branches and branch penalties). However, the mere presence of the branch interferes with compiler optimizations like vectorization.

Let's look a historical example from EnergyPlus. The rarely-used feature is movable insulation. This feature is not commonly used in buildings and as a result it is not commonly used in models either.

MCCF Level 1

The first step of MCCF is to move the handling of Movable Insulation code to a separate loop that is guarded by a condition that there is any Movable Insulation in the model.

if (state.dataSurface->AnyMovableInsulation) {
   for (int SurfNum; 
}

MCCF Level 2

This accomplishes 90% (or maybe 99%) of what we want to do, which is cleaning up the main InitSurfaceHeatBalance loop and making the handling of common surface types fast in all models. If we want to go the last mile (or the last foot maybe) we could make the handling of surfaces with Movable Insulation itself faster by not requiring that code to traverse all surfaces in order to identify those surfaces with Movable Insulation.

Clone this wiki locally