* Re: CXX, templates & performance
1997-08-03 4:00 CXX, templates & performance James CE Johnson
@ 1997-08-08 4:00 ` Phil Edwards
0 siblings, 0 replies; 2+ messages in thread
From: Phil Edwards @ 1997-08-08 4:00 UTC (permalink / raw)
[cc'd to poster]
James CE Johnson <jcej@chiroptera.tragus.org> wrote:
+ I'm hoping somebody out there can give me a hand with this or at least
+ point me to a place that can...
I've been using cxx 5.5-004 for my last two projects, both of which used
templates. One of them (still in progress) uses templates quite heavily,
and I can agree/understand/sympathize with what you've written.
This is a long post. I apologize. There are two suggestions I make, but
they take some examples.
[snip cxx's repository mechanism and the GNUmake's parallel build -- as
it happens, I'm doing the exact same thing]
+ My question is this: Does anybody know what the linker goes through to
+ compile those repository files? I've used `-v' on `ld' and figured out
+ the command lines but it seems that there's some parsing going on which
+ causes new repository files to be created.
Whenever a template is used, the corresponding .cxx and .cmd files are
written into the repository. These tend to be one or two lines each of
source code. (You know this, but I'm reiterating. :-)
At link time, the cxx front end compiler driver invokes a prelinker and
grabs its standard {output,error}. Those lines that we're used to seeing,
"ld:\nUnresolved:\n<pick your favorite function signature>" are caught by
the compiler driver.
Once the prelinker has finished complaining about which functions it
wouldn't have been able to find, the compiler driver has a list of
which repository template files it needs to compile, and does so. Then
it invokes the prelinker again, which will probably find some more
missing object code due to dependancies.
The cxx driver keeps iterating until the prelinker stops complaining.
(Actually, the prelinker will always complain about one particular runtime
symbol from libc.so, but the compiler driver ignores that line.) Once the
prelinker says that it /would have/ been able to do the work, cxx finally
invokes the linker, which then has just the object code it needs to link,
and no more.
Try invoking both the compilation stage and the link stage with the
-ptv option, and redirect stdout/stderr to a file. You'll see cxx get
all chatty about invoking the prelinker, and which templates it's
needing to instantiate.
+ My goal is to figure out how to "manually" build the repository files so
+ that I can stop the compile at the object stage, generate a Makefile in
+ the repository & compile those in parallel then kick back to the linker
+ for the final compile.
Let me suggest one slight alternative: after your next complete, successful
build, ar(1) all of the object files out of the repository into an archive
file, say libwillywonka.a. Future links can pass that file on the command
line, and the prelinker will find those function signatures already
available for use, and therefore won't ask the compiler driver to
instantiate them.
You'll get a repository chock full of 185-byte source files that never get
used, and the link stage will only need to compile two or four templates
(there are some dependancies that /always/ go off, typically with
<string>s).
I happen to be working on my project in another window (Usenet is what
happens while waiting on the compiler, even building in parallel). Here's
the make(1) output for the final line (wrapped for posting):
(cd install && cxx -o server -w0 -I/tmp/work.pedwards/499/include
-ptr ../cxx_repository -non_shared coreinfo.o ../server_src/*.o
/tmp/lib_STUFF.a /tmp/libcxx_phil.a libutils.a libdata.a 2>&1 | demangle);
Note the four archive libraries tossed in at the end. The last two are
built previously in the build process, libcxx_phil.a is my own library of a
bunch of commonly-used templates from the STL, but the first one,
lib_STUFF.a, is nothing but repository object files from previous builds,
days or weeks before. The code in those sectios doesn't change, so there's
no sense in constantly rebuilding them.
Every so often I remove lib_STUFF.a from the link line. About an hour later
the build finishes, and I rebuild lib_STUFF.a out of the fresh repository
files. The old code doesn't change, but occasionally a new template
function has resulted in a few new object files, and those will be added
in. (I rebuild from scratch because I'm paranoid like that. :-)
The second thing I would do is manually instantiate some of your bigger
or commonly-used templates, completely apart from your project. (My
libcxx_phil.a is built like this.) I used a variation of the script
supplied by DEC in the /usr/lib/cmplrs/cxx package; it looks something
like
#include <deque>
template class deque<int>;
template class deque<unsigned int>;
template class deque<char>;
template class deque<char*>;
template class deque<const char*>;
and so on for other kinds of data structures. If this file is inst.C,
then running essentially
cxx -w0 -O -Hf -ptv -ptr /tmp/_inst inst.C
ar rv libcxx_phil.a inst.o /tmp/_inst/*.o
ranlib libcxx_phil.a
gives me an archive library of every possible function needed when using
deque<int>, deque<char>, etc. No link stage will ever need to instantiate
those functions if I happen to use them.
+ If we can get another 10-20% off of the compile times, it might get
+ tolerable!
Keeping those unchanging repository object files across builds has cut about
90% off of the link time. Building for me is now purely a compilation
problem; only rarely am I waiting for more than 15 seconds or so on the
final link.
Luck++;
/dev/phil
^ permalink raw reply [flat|nested] 2+ messages in thread