I notice that with emscripten even relatively small C ++ files can quickly turn into quite huge JavaScript files. Example:
#include <memory> int main(int argc, char** argv) { std::shared_ptr<int> sp(new int); }
Compile this with recent emsdk using a command like
em++ -std=c++11 -s DISABLE_EXCEPTION_CATCHING=1 -s NO_FILESYSTEM=1 \ -s NO_BROWSER=1 -s NO_EXIT_RUNTIME=1 -O3 -o foo.js foo.cc
The resulting file is larger than 400 KB. When resetting -g I can do
grep -n '^function _' foo.js | c++filt -_
and see what features we have. Here are some examples:
std::__1::moneypunct<char, false>::do_thousands_sep() const std::__1::locale::~locale() std::__1::basic_string<wchar_t, …>::~basic_string() std::__1::time_get<…>::__get_day(…) const std::__1::codecvt<wchar_t, char, __mbstate_t>::codecvt(unsigned int) std::__1::locale::__imp::install(std::__1::locale::facet*, long) _printf_core
I myself do not call this, but nonetheless, all functions are included. Probably many of them are included in some kind of virtual function table. Others may be associated with some kind of static initializer.
If it was regular code associated with one shared library somewhere on my hard drive; I would not mind. But half the megabyte in the JavaScript code that needs to be transmitted is only for one common pointer? There must be a way to avoid this.
source share