I thought Erlang would optimize the ++ operator when the left side is known at compile time.<div><br></div><div>For example, if the compiler sees the following outside of a function signature:<br><div><br></div><div><div> "Foo" ++ Bar</div>
<div><br></div><div>It could rewrite it as:</div><div><br></div><div> [$F, $o, $o | assert_list(Bar)]<br clear="all"><div><br></div><div>However, I ran some benchmarks and it seems the optimization does not happen (on R15B).</div>
<div>With a local dummy implementation of assert_list(Bar), I got that the first format is 50% slower than the second one.</div><div><br></div><div>That said, given the possibility something is odd in my setup, does Erlang optimize it or not? If not, could it?</div>
<div><br></div><div><br></div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b><span style="border-collapse:separate;font-family:arial;font-weight:normal"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div><span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div>
<div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Lead Developer</span></div></span></div></span></b></span><br>
</div></div></div>