[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Compile time increases quadratically with struct size

>Submitter-Id:	net
>Originator:	Zoltan Hidvegi
>Confidential:	no
>Synopsis:	Compile time increases quadratically with struct size
>Severity:	critical
>Priority:	medium
>Category:	c++
>Class:		sw-bug
>Release:	gcc version 3.3 20030512 (prerelease)
System: x86/Linux & PowerPC/AIX

Name lookups for struct members use linear search, which can result in
quadratic compile time increase.  See also c/10675:

This happens in both c and c++, but I can only specify one category.

The following is a shell script that will generate a struct with a
given number of members and a functions that assings zero to all

------- BEGIN biggen.sh -------------
#! /bin/sh
let i=0
echo 'struct foo {'
while [ "$i" -lt "$1" ]
    echo "    int i_$((i=i+1));"
echo '};'
#echo 'struct foo f;'

let i=0
echo 'void init_foo(struct foo *p) {'
while [ "$i" -lt "$1" ]
    echo "    p->i_$((i=i+1)) = 0;"
echo '}'
--------- END biggen.sh -------------

Run it like this:
./biggen.sh 10000 > big.C; time g++ -c big.c
Change the number from 10000 and see how the compile time is
affected.  Also watch the memory usage, e.g. with 25000 members it
needs 55M, but the memory usage scales linearly.


Reply to: