[llvm-bugs] [Bug 40512] New: Binary size exploding when using a lambda in a template with multiple parameters
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jan 29 02:37:55 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=40512
Bug ID: 40512
Summary: Binary size exploding when using a lambda in a
template with multiple parameters
Product: new-bugs
Version: 7.0
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: mjklaim at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
Created attachment 21400
--> https://bugs.llvm.org/attachment.cgi?id=21400&action=edit
Sources of the test, see instructions in the comments.
We observe, when testing locally and on on Compiler Explorer, binary sizes
growing significantly in the attached test.
Related MSVC report:
https://developercommunity.visualstudio.com/content/problem/435436/binary-size-exploding-6x-when-using-a-lambda-in-a.html
To observe the issue, compile with and without defining INDEPENDENT_TYPE (on
command line or by adding the define in the source) and compare the resulting
binary sizes.
lambda-gen.zip contains the source of the test.
What the test does: we have a template struct which have multiple parameters,
and we use a function of that struct that calls a lambda which only use one of
the parameters. If we replace the lambda by an independent type with one
template parameter, we observe a significant binary size reduction.
We tested on Compiler Explorer and we can observe for all compilers, the
difference is at least 2 times (more for MSVC).
Clang (trunk) 64bit (-O2):
- With `-DINDEPENDENT_TYPE: https://godbolt.org/z/CNPveT
- Without `-DINDEPENDENT_TYPE: https://godbolt.org/z/iSKYyJ
You can see in the bottom bar of the assembly output window there is a
"Compilation time (Result Size)" field on which we based our measurements.
>From the generated assembly code (visible on Compiler Explorer) we assume that
none of these compilers detect that the lambda is dependent only on one type,
therefore no special optimization is done to result with a similar result than
when we explicitly use a templated struct instead. So for each permutation of
the main template struct parameters, we end up with 1 generated lambda type,
when only one is actually used.
As this is an issue with all compilers, this is very unfortunate as we would
prefer to express this code with lambdas in a majority of situations in generic
code.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190129/43430430/attachment-0001.html>
More information about the llvm-bugs
mailing list