2012/11/15 Junchang Wang
<junchangwang@gmail.com>
I printed out the call stack (attached at the tail of this email). It seems for a single packet processing there are more than 30 function calls within Boost. Can that explain why the CPU time on function calls is so high? Are there some ways to avoid this kind of cost?
It's the price to pay for ASIO abstraction. But, compiling with -O3 should inline some calls, what you see is debugging not inlined code.
you can try to reduce the call stack with gcc parameter "-finline-limit=" and try various numbers to see if it reduces function calling times.
Another way to reduce this is by using your compiler optimised std::bind and std::function. Sometimes they are more efficient than the one provided by boost. (and maybe change all occurences of "boost::bind" / "boost::function" in boost.asio with their "std" alternative.
You can also check that your compiler is c+11 compliant and implement perfect forwarding and try to pass your parameters by reference where it is possible to lower copying cost with multiple function calls.