Yeah, any c++ standard library feature can lead to a large increase in code size, as it ends up linking in big parts of libc++.
Optimally, it would be nice if upstream libc++ were refactored to avoid that, but I have no idea how feasible that would be both technically and not. Alternatively, you can use your own custom String class instead of std::string. You can then make sure it doesn't handle locales and the other complexity that causes big parts of libc++ to get lumped in. Otherwise, some compiler opts might help. On a hello world using an std::string and -Os, I see 91K output (similar to you). With --closure 1 I see 72K (at the cost of a slower build time) and with --closure 2 I see 66K (at the cost of both slower build time and slower runtime as it disables asm.js). Longer-term, wasm will help here. I see the compiled code in that format is 30K (however, we currently disable minifying the JS part, which we need to fix). On Mon, Nov 7, 2016 at 1:18 PM, 'Ben Vanik' via emscripten-discuss < [email protected]> wrote: > My resulting asmjs outputs are massive and it's making me sad! I've > tracked most of the size down to ios_base's global initializer (and the > world that it pulls in) -- even though I'm not using iostream (or really > much of anything) and was wondering if anyone had a way to get around this. > > My hello world sample compiles to 6KiB, but if I include <string> and add > a single `std::string foo;` it jumps up ~100KiB (even in -O2 with > --llvm-lto 1). > The big difference in output comes down to this: > ``` > function __GLOBAL__I_000101() { > var label = 0, sp = 0; > sp = STACKTOP; > __ZNSt3__18ios_base4InitC2Ev(0); > return; > } > + a billion functions called by ios_base::Init. > ``` > > That ios_base::Init pulls in locale and a bunch of other stuff that is > only ever called from that stack. Because it's a global initializer > dead-code removal won't get rid of it and it ends up in my final output. It > seems a bit silly that even when not using iostream > (cin/cout/strstream/etc) I still take a massive hit. > > I found this issue from a year or so ago which seems like exactly what I'm > seeing: > https://github.com/kripken/emscripten/issues/2545 > > Unfortunately the fix proposed never made it in: https://github.com/ > kripken/emscripten/pull/3308 > > Besides not using std::string anywhere (which is extremely difficult given > the code I'm compiling) has anyone found solutions for removing this bloat? > Is there any emscripten features (in-progress or planned) that will help > situations like this? > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
