<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Binary size exploding when using a lambda in a template with multiple parameters"
href="https://bugs.llvm.org/show_bug.cgi?id=40512">40512</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Binary size exploding when using a lambda in a template with multiple parameters
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>7.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mjklaim@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=21400" name="attach_21400" title="Sources of the test, see instructions in the comments.">attachment 21400</a> <a href="attachment.cgi?id=21400&action=edit" title="Sources of the test, see instructions in the comments.">[details]</a></span>
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:
<a href="https://developercommunity.visualstudio.com/content/problem/435436/binary-size-exploding-6x-when-using-a-lambda-in-a.html">https://developercommunity.visualstudio.com/content/problem/435436/binary-size-exploding-6x-when-using-a-lambda-in-a.html</a>
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: <a href="https://godbolt.org/z/CNPveT">https://godbolt.org/z/CNPveT</a>
- Without `-DINDEPENDENT_TYPE: <a href="https://godbolt.org/z/iSKYyJ">https://godbolt.org/z/iSKYyJ</a>
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>