6 ms·
I wonder how much the size of the compiled code increased --- it's been my experience that "C++-ifying" tends to bloat the binaries quite a bit. "Zero cost abs
by userbinator 5y ago
I wonder how much the size of the compiled code increased --- it's been my experience that "C++-ifying" tends to bloat the binaries quite a bit.
"Zero cost abstractions" are, in practice, quite rare.
- jupp0r 5y agoProbably a bit. Monomorphization is expensive in terms of code size. On the other hand - why would you care for a couple of 100kb for a use case like transmission?
- userbinator 5y agouTorrent, a whole torrent client I remember using many years ago, was only ~100k in total.
- aeyes 5y agouTorrent is on the same page as Transmission before this change, it achieves its small size by not using the STL at all.
- userbinator 5y agoAll sources I've found indicate that uTorrent was written in C++, but perhaps its author was a bit more mindful of unnecessary abstraction and the like.
- mhh__ 5y agoThis is worth keeping in mind, but the real issue is the pressure on the optimizer and linker rather than size IMO.
- IshKebab 5y agoZero cost abstractions are about performance, not code size.
- userbinator 5y agoCode size definitely affects performance, and has done so ever since caches existed.
- pjmlp 5y agoI advise a talk from Chandler Carruth where he proves longer code can achieve higher performance due to the way computer architectures work. Unfortunately I no longer remember in which conference he did it, maybe someone else can link it.
- userbinator 5y agoIn microbenchmarks, on a long pipeline RISC, or similar microarchitectures like NetBurst (P4), I could see that being true. But we're long past that era now. It's the same misguided assumptions that leads to several-KB-long "optimised" memcpy() implementations whose real-world effects on performance are negligible to negative. If you don't believe me, read what Linus Torvalds has to say about why the Linux kernel is built with -Os by default.
- pjmlp 5y agoHe did it on x64. EDIT: This is the talk, if I remember correctly. https://isocpp.org/blog/2018/06/cppcon-2017-going-nowhere-faster-chandler-carruth https://isocpp.org/blog/2018/06/cppcon-2017-going-nowhere-fa...
- ncmncm 5y agoMy recent tests with -Os resulted in distinctly negative effects on performance. But the main problem with -Os is that it is poorly exercised. The best-exercised modes are -O0 and -O2, so those are the ones to use in production.
- junon 5y ago> My recent tests with -Os resulted in distinctly negative effects on performance. Err... yeah, because -Os means "optimize size". Not "speed". > But the main problem with -Os is that it is poorly exercised No, the main problem is that you don't understand -Os :) It works as intended.
- jdright 5y agoIt is a common mistake what you're doing by generalizing it out of the original scope, which is only performance wise. Any other aspect you might think is not encompassed into the original zero cost abstraction concept.
- josefx 5y agoMost of that is probably in some symbol table used by the linker. C++ symbols include type names for parameters, C compilers only contain a function name, its linker literally can't tell the difference between a char main[10] and int main(int,char*){} because both are compiled to "main" .
- bregma 5y agoThis is important. The size of the stripped binaries should be compared. ELF binaries contain both link-time sections and loadable segments, and the longer name of C++ symbols only affects disk space (for both the link-time symbol table and for debug information). The size of the runtime-loadable segments is really the only thing of interest, and stripping the binaries gives you a truer indication of this.
- rwmj 5y agoJust built both versions for you. Edit: Please note the C++ code change doesn't actually use the STL, it really just changes the compiler and code style in a few places. So I don't think this represents any argument for or against C vs C++. -rwxr-xr-x. 1 rjones rjones 4167912 Sep 12 22:09 build-c++/gtk/transmission-gtk -rwxr-xr-x. 1 rjones rjones 3997408 Sep 12 22:12 build-c/gtk/transmission-gtk -rwxr-xr-x. 1 rjones rjones 3130352 Sep 12 22:09 build-c++/daemon/transmission-daemon -rwxr-xr-x. 1 rjones rjones 2959640 Sep 12 22:12 build-c/daemon/transmission-daemon build-c++/utils/: total 12156 drwxr-xr-x. 6 rjones rjones 4096 Sep 12 22:08 CMakeFiles -rw-r--r--. 1 rjones rjones 5653 Sep 12 22:08 cmake_install.cmake -rw-r--r--. 1 rjones rjones 289 Sep 12 22:08 CTestTestfile.cmake -rw-r--r--. 1 rjones rjones 13793 Sep 12 22:08 Makefile -rwxr-xr-x. 1 rjones rjones 3082448 Sep 12 22:09 transmission-create -rwxr-xr-x. 1 rjones rjones 3066256 Sep 12 22:09 transmission-edit -rwxr-xr-x. 1 rjones rjones 3182928 Sep 12 22:09 transmission-remote -rwxr-xr-x. 1 rjones rjones 3073952 Sep 12 22:09 transmission-show build-c/utils/: total 11496 drwxr-xr-x. 6 rjones rjones 4096 Sep 12 22:12 CMakeFiles -rw-r--r--. 1 rjones rjones 5645 Sep 12 22:12 cmake_install.cmake -rw-r--r--. 1 rjones rjones 287 Sep 12 22:12 CTestTestfile.cmake -rw-r--r--. 1 rjones rjones 13725 Sep 12 22:12 Makefile -rwxr-xr-x. 1 rjones rjones 2917136 Sep 12 22:12 transmission-create -rwxr-xr-x. 1 rjones rjones 2895128 Sep 12 22:12 transmission-edit -rwxr-xr-x. 1 rjones rjones 3014872 Sep 12 22:12 transmission-remote -rwxr-xr-x. 1 rjones rjones 2901832 Sep 12 22:12 transmission-show
- userbinator 5y agoThanks for the proof. Over 100k increase on average. Not surprising. ...and people wonder why software gets slower and bigger over time while doing the same thing. We even get HN articles about that semi-regularly.
- rwmj 5y agoA question that I'd like to ask a C++ expert: If you use any STL container, is it always the case that the whole thing is templated, therefore effectively compiled and statically linked into the binary? Or will part/all of it come from functions in the dynamically linked libstdc++.so?