Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio C++ enum takes a long time to compile

I have a dll with an enum (and many other things)

enum class KIT_API VoxelTypes : uint16_t
{
  ... about a hundred entries ...
    ModellingClay_00 = 65406,
... more entries ...
    ModellingClay_128,
    COUNT
};

The value of element COUNT is 65535. I've been compiling this for over 45 minutes at the "Generating Code" stage. If I set ModellingClay_00 to 10000, it compiles in about 5-10 minutes. 15000 seems to take quite a bit longer, but did eventually compile.

Is there any reason an enum should take vastly longer to compile simply from changing the value it contains?

I'm pretty sure I've run afoul of some inner voodoo of Visual Studio set aside for my personal torment. Can anyone point out something obvious I've done, or even heard of this before?

like image 389
NapkinTrout Avatar asked Sep 22 '17 07:09

NapkinTrout


1 Answers

Angew's analysis is correct.

There was a static array of VoxelTypes::COUNT elements. Each element was 88 bytes, for a total of 5,767,168 (5.5 Mb).

My work-around was to create an array of dynamic arrays instead of using a massive table of array initializers.

Old:

static Elements whoppingBigTable[] = {
    {Item1, 1, 1},
    {Item2, 2, 2},
};

New:

static Elements* whoppingBigTable[64];
for(int i = 0; i < 64; i++)
{
    whoppingBigTable = new Elements[1024];
}
AddElement({Item1, 1, 1});
AddElement({Item2, 2, 2});

Also had to add some math function to access the array elements. I assume that this is the fastest way to do it. It contains the definitions of my voxels, so I need to access it frequently. (I suppose I could also define separate arrays for each voxel property, and those arrays might be small enough to compile. That might be even faster than putting all properties into one giant array)

const Element& GetWhoppingElement(int index)
{
    int majorIndex = index / 1024;
    int minorIndex = index % 1024;
    return whoppingBigTable[majorIndex][minorIndex];
}
like image 109
NapkinTrout Avatar answered Oct 29 '22 09:10

NapkinTrout