[cfe-dev] Binary size when using std::function with lambda expression

Csaba Raduly via cfe-dev cfe-dev at lists.llvm.org
Fri Jan 8 04:59:20 PST 2021


Hi Cyril,

https://godbolt.org/z/vv3xWP   generated 467 lines of assembler with clang
trunk and -O0 (on Linux, I suppose), versus 58 lines for the function
pointer.

With -O2 it was 76 lines vs 20 lines.
(Nine lines are always used to initialize iostream and set up its
destruction)

There may be extra code linked in from libc++ for std::function.

Csaba


On Fri, 8 Jan 2021 at 11:45, Cyril Makloufi via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hello,
>
>
> When using std::function instead of function pointer (see the sample of
> code) on Mac, we get a huge difference between size of generated binary
> (80ko when using function pointer and 157ko whit std::function).
>
> I use Xcode to build debug with -O0 -std=gnu++14 and libc++.
>
> It doesn't seem to have the same result on windows or linux.
>
> Is it something normal ?
>
>
> Here's the code sample :
>
>
> #include <iostream>
>
> #include <functional>
>
>
>
> *int* main(*int* argc, *const* *char* * argv[]) {
>
>     std::function<*void*()> f = [](){std::cout << "LOG2\n";};
>
> //    void (*f)() = [](){std::cout << "LOG3\n";};
>
>
>
>     f();
>
>
>
>     *return* 0;
>
> }
>
>
> Thanks,
>
> Cyril
>
> Cyril Makloufi
> Développeur
> Email : Cyril.Makloufi at 4d.com
> Web : www.4d.com
> 4D SAS
> 66 route de Sartrouville
> Parc Les Erables - Batiment 4
> 78230 Le Pecq - France
> Standard : +33 1 30 53 92 00
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>


-- 
You can get very substantial performance improvements
by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
So if you're looking for a completely portable, 100% standards-conformant
way
to get the wrong information: this is what you want. - Scott Meyers
(C++TDaWYK)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210108/8c01f4d2/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image0b65ab.JPG
Type: image/jpeg
Size: 4989 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210108/8c01f4d2/attachment-0001.jpe>


More information about the cfe-dev mailing list