4 ms·
Author here. I don't know why my own submission of this [1] didn't catch and this one did. Oh well. XD I'm open to answering questions, and I'll be hanging in
by ghoward 5y ago
Author here. I don't know why my own submission of this [1] didn't catch and this one did. Oh well. XD
I'm open to answering questions, and I'll be hanging in the thread.
[1]: https://news.ycombinator.com/item?id=28728801 https://news.ycombinator.com/item?id=28728801
- comex 5y agoI am extremely skeptical of this calculation by Drew DeVault: > On average, dynamically linked executables use only 4.6% of the symbols on offer from their dependencies. A good linker will remove unused symbols. Percent of exported symbols used is a terrible proxy for percent of library functionality used. As an example, an SDL hello world program [1] uses 3 functions out of 750 exported by libSDL2. Does that mean it only uses 3/750 = 0.4% of libSDL2's functionality? Of course not; when I tried compiling it against a static libSDL2 instead of dynamic, the executable's binary size increased by a full 70% of the size of libSDL2.so. [2] Now, on one hand I admit that's an extreme example, as a real SDL program would use a higher number of functions. And SDL itself is not very amenable to dead code stripping; a good chunk of the hello-world program is for things like sound or input that the it doesn't actually use. Still, even the hello-world program legitimately needs a bunch of functionality, including support for both X11 and Wayland, and setting up hardware accelerated surfaces using OpenGL. And a real program would need more. Also, I'm not even counting the long list of shared libraries linked by SDL (ranging from libX11 to libFLAC); a SDL-based program will use 0% of their symbols (since it doesn't them directly), but may need a substantial portion of their functionality. More importantly, this general pattern, where exported APIs are just the tip of the iceberg, applies to many libraries. I tried a similar experiment with zpipe, the official example program for zlib – a much smaller and shallower library. It ended up using 23% of symbols but 53% of the implementation. On the other end of the spectrum, the problem would be far worse with a real GUI library, where even, say, a simple text input box truly requires massive amounts of functionality including display, layout, Unicode font rendering, menus, internationalization, and keyboard and mouse input. Plus, of course, a variety of input method editors if you want to support languages like Japanese. In a statically linked world you would probably want to implement most of that as IPC to shared daemons. Such a design could work; there isn't much that really needs the performance benefits of being in-process. But no major GUI libraries are written that way, because in a world with shared libraries there's no need. [1] https://gist.github.com/comex/c64b5a7e409d5d48ad6ebf37ec068b03 https://gist.github.com/comex/c64b5a7e409d5d48ad6ebf37ec068b... [2] Test harness also at [1]. This is with LTO; without LTO the percentage is much higher. I also had to disable SDL's "dynapi" feature that makes static linking secretly actually dynamically link. Which they put in for good reasons, albeit mostly applicable only to proprietary software where the user can't just recompile/relink.