C++: a bigger pile of shite

[prev] [thread] [next] [lurker] [Date index for 2006/06/17]

From: Yossi Kreinin
Subject: C++: a bigger pile of shite
Date: 11:26 on 17 Jun 2006
I'm working on this fairly large embedded system. Recently we decided
that maybe it's even too large, and how about making it smaller.

So people cleaned things up, and everyone was happy. The other day we
built it, and the image is 800K larger compared to the size that made
us happy.

I wrote a script to tell us how much code was compiled from each
directory in the source tree. It looks for `bof..' and `eof..'
symbols kindly generated by our compiler at the beginning and the end
of each translation unit. The source filename is mangled so that
slashes become `.2F' and so on. Elegant and portable, pretty much
like the rest of C/C++.

So we run it on the two binaries and it turns out that iostream used
to take only 400K, but now it's grown to 1.2M. That's not too much
for a state of the art formatting library: after all, Embedded Linux
takes 2M. And it was easy to get these 800K back: all you need to do
is comment out the instantiations of basic_{i,o}stream with wchar_t
and unsigned short in the library source (BTW, wchar_t is unicode,
but what the fuck is unsigned short?!). Of course it would give us
 >200K in the old version, which is also notable.

But I was still puzzled why it changed without anyone touching it
(can you imagine someone touching THIS shit?). So I look deeper into
the object files, which have names like ostream__sti0_97abf70.o.
I list the symbols and fire an editor. A function named _Iput or
something catches my eye: it takes, say, 14K. Must be very useful,
thinks I to myself. Let's look how many instantiations of that we've
got.

I search for `_Iput' - and the screen doesn't move. Try again and
again - nothing. Did this piece of shit workstation hang again? Wait,
something is flickering at the bottom of the screen. That's the line
number! WHAT?! I see the same screen 10 times around _Iput? DO YOU
MEAN THAT ALL OF THIS _(&^$*@_(1) BULLSHIT IS REPLICATED 10 TIMES
IN MY IMAGE?? And I was looking for DIFFERENT instantiations - how
NAIVE!

This is actually even better than that. First, the replicas DON'T
LIST in the symbol table: they show up as unnamed gaps BETWEEN
symbols. Second, we've already spent quite some time trying to
convince the compiler to keep ONE copy of every function: we've
found FLAGS for that (by default, it keeps multiple copies of
templates, and then has the NERVE to COMPLAIN about having them,
so you have to tell the linker to IGNORE MULTIPLE DEFINITIONS).
Now I see how the flags work: it keeps replicating, but without
the whining.

And that doesn't even count the INLINED code! When you compare
a std::string with a character literal, you get to see assembly
code the size of a human head listed near that source line.
And no, that's not all - it calls about 3 functions to help it.

Do the fuckers who promote STL realize that CODE TAKES FUCKING
SPACE? Maybe they are idealist philosophers and assume that code
lives in a separate realm of ideas and notions. And how is it
possible to implement a compiler so lousy it just HAS to keep
10 copies of each instantiation, unless you do it on purpose?

C++: kind of like C, but much bigger.

(1) People with C++ experience know that these characters are not
necessarily a censored profanity - they may as well be a perfectly
legal mangled symbol name.

Generated at 22:00 on 18 Jun 2006 by mariachi 0.52