zaphoyd / websocketpp

C++ websocket client/server library
http://www.zaphoyd.com/websocketpp
Other
7.04k stars 1.97k forks source link

Very slow buid #269

Open abrkn opened 11 years ago

abrkn commented 11 years ago

I'm currently including websocketpp like in the demo, by passing -I ~/websocketpp to g++. The problem is that I'm running this on a Raspbian (Raspberry PI) and it takes a few minutes to build. Is there a way to pre-build websocketpp? I'm not yet very familiar with C++.

zaphoyd commented 11 years ago

WebSocket++ is a header only library that makes significant use of template based generic programming. This provides a boost to runtime speed and memory performance and provides a lot more type information used for compile time optimization and error checking. Additional compiling time is a tradeoff of this architecture (doing more at compile time so there is less work/errors at runtime)

By default, this means that any time you change the translation unit (usually meaning cpp file) that defines your endpoints, all of the endpoint code will get recompiled. If you use the endpoint in multiple translation units it will get recompiled once for every one.

Some of this is necessary and unavoidable other parts aren't. If you are changing anything in your endpoint's config template parameter then all endpoint code must be recompiled as config changes alter the types the library uses to generate the endpoint. If you have access to a C++11 compiler (or a compiler that has an extern template extension) you should be able to instantiate your configured endpoint in one translation unit and use extern templates to avoid duplicating that work when compiling other source files.

I'll look into creating an example based on the c++11 extern template feature.

ghost commented 4 years ago

Hi. The header approach is a bit problematic on systems with low memory. E.g. compiling even a simple tiny tls enabled websocket uses more than 512MB on an rpi zero causing heavy swapping (on an sd card!).