incredibly long linking time with optimizations enabled

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div style="color:black; background-color:white
<pre><span style="color:green //consider the following program<br/><br/>#include "stdint.h"

#include <span style="color:#a31515 "stdio.h"

<span style="color:blue enum mon_resist_flags
{
MR_VUL_POISON = 0,
};
<span style="color:blue struct mon_resist_def
{
<span style="color:blue short elec;
<span style="color:blue short poison;
<span style="color:blue short fire;
<span style="color:blue short steam;
<span style="color:blue short cold;
<span style="color:blue short hellfire;
<span style="color:blue short acid;

<span style="color:blue bool asphyx;
<span style="color:blue bool sticky_flame;
<span style="color:blue bool rotting;

<span style="color:green // Physical damage resists (currently unused)
<span style="color:blue short pierce;
<span style="color:blue short slice;
<span style="color:blue short bludgeon;
mon_resist_def(mon_resist_flags flag):elec(0),poison(0),fire(0),steam(0),
cold(0),hellfire(0),acid(0),asphyx(<span style="color:blue false),
sticky_flame(<span style="color:blue false),rotting(<span style="color:blue false),pierce(0),slice(0),bludgeon(0)
{}

};

<span style="color:blue enum mon_attack_type
{
AT_BITE
};
<span style="color:blue enum mon_attack_flavour
{
AF_POISON
};
<span style="color:blue struct mon_attack_def
{
mon_attack_type type;
mon_attack_flavour flavour;
<span style="color:blue int damage;

};
<span style="color:blue struct mon_energy_usage
{
<span style="color:blue public:
int8_t move;
int8_t swim;
int8_t attack;
int8_t missile; <span style="color:green // Arrows/crossbows/etc
int8_t spell;
int8_t special;
int8_t item; <span style="color:green // Using an item (i.e., drinking a potion)

<span style="color:green // Percent of mons->speed used when picking up an item; defaults
<span style="color:green // to 100%
int8_t pickup_percent;
};
<span style="color:blue enum COLORS {
RED
};
<span style="color:blue enum monster_type
{
MONS_WORKER_ANT
};
<span style="color:blue enum mon_holy_type {
MH_NATURAL
};
<span style="color:blue enum mon_intel_type
{
I_INSECT
};
<span style="color:blue enum corpse_effect_type
{
CE_CLEAN
};
<span style="color:blue enum zombie_size_type
{
Z_SMALL
};
<span style="color:blue enum flight_type
{
FL_NONE
};
<span style="color:blue enum habitat_type
{
HT_LAND
};
<span style="color:blue enum size_type
{
SIZE_SMALL
};
<span style="color:blue enum shout_type
{
S_SILENT
};
<span style="color:blue enum mon_itemuse_type{
MONUSE_NOTHING
};
<span style="color:blue enum mon_itemeat_type{
MONEAT_NOTHING
};
<span style="color:blue const uint64_t M_NO_SKELETON = 1<<30;
<span style="color:blue struct monsterentry
{
<span style="color:blue short mc; <span style="color:green // monster number

<span style="color:blue char showchar;
uint8_t colour;
<span style="color:blue const <span style="color:blue char *name;

uint64_t bitfields;
mon_resist_def resists;

<span style="color:blue short weight;

int8_t exp_mod;

monster_type genus,
species;

mon_holy_type holiness;

<span style="color:blue short resist_magic;
mon_attack_def attack[4];

<span style="color:blue unsigned hpdice[4];

int8_t AC; <span style="color:green //
int8_t ev; <span style="color:green //
<span style="color:blue int sec; <span style="color:green //
corpse_effect_type corpse_thingy;
zombie_size_type zombie_size;
shout_type shouts;
mon_intel_type intel;
habitat_type habitat;
flight_type fly;
int8_t speed;
mon_energy_usage energy_usage;
mon_itemuse_type gmon_use;
mon_itemeat_type gmon_eat;
size_type size;
};


<span style="color:blue const mon_energy_usage DEFAULT_ENERGY;
<span style="color:blue static monsterentry mondata[] = {

#include <span style="color:#a31515 "denemedata.h"
};

<span style="color:blue int main(<span style="color:blue int argc, <span style="color:blue char *argv[])
{
printf(<span style="color:#a31515 "size of mondata %d",<span style="color:blue sizeof(mondata)/<span style="color:blue sizeof(monsterentry));
}

[/code]

and the denemedata.h is as follows

<div style="color:black; background-color:white
<pre>{
MONS_WORKER_ANT, a, RED, <span style="color:#a31515 "worker ant",
M_NO_SKELETON,
MR_VUL_POISON,
450, 10, MONS_WORKER_ANT, MONS_WORKER_ANT, MH_NATURAL, -3,
{ {AT_BITE, AF_POISON, 8}},
{ 3, 3, 5, 0 },
4, 10, 0, CE_CLEAN, Z_SMALL, S_SILENT,
I_INSECT, HT_LAND, FL_NONE, 12, DEFAULT_ENERGY,
MONUSE_NOTHING, MONEAT_NOTHING, SIZE_SMALL

},
[/code]

*500 times

Ive ripped it from a project I am porting to MSVC. when I build the above program
in debug mode I get;
624 ms Link
1 calls<br/>
2520 ms CL
1 calls<br/>
<br/>
Build succeeded.<br/>
<br/>
Time Elapsed 00:00:03.42
all is well, but when in release mode
761 ms CL
1 calls<br/>
219836 ms Link
1 calls<br/>
<br/>
Build succeeded.<br/>
<br/>
Time Elapsed 00:03:40.69

same program with g++
$ time g++ deneme.cc -O2 -o dengg<br/>
<br/>
real 0m3.396s<br/>
user 0m0.000s<br/>
sys 0m0.015s
the link time increases exponentially with the number of
entries in denemedata.h. if I remove the constructor in mon_resist_def (also putting the MR_VUL_POISON in a initializer list of course)
then it links it in half time ,but still very long.
Any ideas why that might be?

Edit : using MSVC10
also
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86<br/>
Copyright (C) Microsoft Corporation. All rights reserved.<br/>
<br/>
Microsoft (R) Incremental Linker Version 10.00.30319.01<br/>
Copyright (C) Microsoft Corporation. All rights reserved.




<br/>

View the full article
 
Back
Top