<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="270253" data-post-id="270253">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hst337" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hst337
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>And this is a great space for optimization my compiler is targeting.</p>
<p>Optimizing <code>for</code>, <code>Enum</code> pipes, plaining nested <code>case</code>-s and removing <code>x.y</code> runtime should give around 20% performance increase for Elixir code</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270253" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-270253" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270253"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #31"></div>
  </section>
</div>
    <div class="postbit" id="270255" data-post-id="270255">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="bjorng" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bjorng/120/13187_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  bjorng
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="30" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>As far as I know, Erlang does not perform this. It generally eliminates stack frames as part of body recursion but it does not perform any special behaviour for lists</p>
</blockquote>
</aside>
<p>Your are right. The Erlang compiler does not do this optimization. It does attempt to keep the stack frame as small as possible when recursing, trimming the stack frame when possible.</p>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="30" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>However, my knowledge may be out of date. Maybe the JIT performs new tricks?</p>
</blockquote>
</aside>
<p>Nope, no new tricks for body recursion.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270255" data-batch-url="/posts/batch_likers">
                        5
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-270255" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270255"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #32"></div>
  </section>
</div>
    <div class="postbit" id="270792" data-post-id="270792">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="hst337" data-post="32" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/41988e/48.png" class="avatar"> hst337:</div>
<blockquote>
<p>Optimizing <code>for</code>, <code>Enum</code> pipes, plaining nested <code>case</code>-s and removing <code>x.y</code> runtime should give around 20% performance increase for Elixir code</p>
</blockquote>
</aside>
<p><code>Enum</code> pipes is hard to optimize without changing semantics.</p>
<p>We can optimize <code>for</code> though. The only way I know how to optimize it though requires doubling its body in the source code based on the generators. Unless we emit some sort of special <code>Kernel.Utils.for</code> for the cases <code>for</code> works on a single collection?</p>
<p>Plaining nested cases is interesting and perhaps even a feature the Erlang/OTP team could be interested in?</p>
<p>And I am definitely curious about the <code>x.y</code> stuff. <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>Looking forward to learn more!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270792" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/34">Post #33</a>
	                </div>
	            </div>
              <div id="likers-container-270792" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270792"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #33"></div>
  </section>
</div>
    <div class="postbit" id="270804" data-post-id="270804">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hst337" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hst337
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="34" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p><code>Enum</code> pipes is hard to optimize without changing semantics.</p>
</blockquote>
</aside>
<p>Yes, it is hard, but it is not impossible. Right now, I know that these optimizations are possible:</p>
<ol>
<li>Convert <code>sum</code>, <code>count</code>, <code>product</code>, <code>frequencies</code> to <code>Enum.reduce</code></li>
<li>Join <code>zip</code> and <code>reduce</code> to <code>zip_reduce</code></li>
<li>When one of steps is pure, I can join <code>filter</code> and <code>filter</code>, <code>filter</code> and <code>map</code>, <code>map</code> and <code>map</code>, <code>map</code> and <code>reduce</code>, <code>filter</code> and <code>reduce</code>, <code>flat_map</code> and <code>flat_map</code>, <code>flat_map</code> and <code>reduce</code>, <code>filter</code> and <code>each</code>, <code>map</code> and <code>each</code></li>
<li>Optimize <code>for</code> to plain <code>map</code>. In my compiler this optimization looks like this:</li>
</ol>
<pre data-code-wrap="elixir"><code class="lang-elixir">  def join_consecutive([{:lists, :reverse, []} = reverse, {Enum, :reduce, [[], reducer]} = reduce | tail]) do
    case reducer do
      tri(fn x, acc -&gt; [body | acc] end) -&gt;
        [{Enum, :map, [tri(fn x -&gt; func end)]} | join_consecutive(tail)]

      _ -&gt;
        [reverse, join_consecutive([reduce | tail])]
    end
  end
</code></pre>
<ol start="5">
<li><code>filter</code> and <code>empty?</code> can be joined</li>
<li>If I know that <code>Enum.reduce</code> is definitely called upon a list, I can replace call with <code>:lists.foldl</code>, which will reduce 1 call, but more importantly, will be efficiently inlined by Erlang compiler</li>
<li><code>Enum.into(%{})</code> with fn or <code>map</code> to <code>Map.new</code></li>
</ol>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="34" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>Plaining nested cases is interesting and perhaps even a feature the Erlang/OTP team could be interested in?</p>
</blockquote>
</aside>
<p>Yeah, but this is a hardest optimization I am working on. Benchmarks show that there is almost no general rule where this optimization would increase performance. So, this is only for code size reduction, and must use some profiles, for which I need an infrastructure</p>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="34" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>And I am definitely curious about the <code>x.y</code> stuff. <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
</blockquote>
</aside>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule X do

  def dot(map) do
    [
      map.x + map.y,
      map.y + map.x,
      map.x + map.y,
      map.y + map.x,
      map.x + map.y,
      map.y + map.x,
    ]
  end

  def mapdot(%{} = map) do
    [
      map.x + map.y,
      map.y + map.x,
      map.x + map.y,
      map.y + map.x,
      map.x + map.y,
      map.y + map.x,
    ]
  end

  def match(%{x: x, y: y}) do
    [
      x + y,
      y + x,
      x + y,
      y + x,
      x + y,
      y + x,
    ]
  end

end

Benchee.run(%{
  "dot" =&gt; fn -&gt; X.dot(%{x: 1, y: 1}) end,
  "mapdot" =&gt; fn -&gt; X.mapdot(%{x: 1, y: 1}) end,
  "match" =&gt; fn -&gt; X.match(%{x: 1, y: 1}) end,
}, warmup: 1, time: 2)

"""
match        21.30 M       46.96 ns ±62508.26%           0 ns          88 ns
mapdot       20.62 M       48.51 ns ±60512.81%           3 ns          85 ns
dot           7.10 M      140.75 ns ±16462.57%          63 ns         206 ns

Comparison:
match        21.30 M
mapdot       20.62 M - 1.03x slower +1.55 ns
dot           7.10 M - 3.00x slower +93.80 ns
"""
</code></pre>
<p>So, compiler can optimize the code which uses <code>.</code> and it know that the <code>map</code> is map, however, compiler generates code which performs check <strong>each-time</strong> if it can’t prove that the variable <code>map</code> contains map (and not module).</p>
<p>So, there are two optimizations possible.</p>
<ol>
<li>Prove that the <code>map</code> is always a map. The simplest way to do this is to check if there is a module with such functions, haha</li>
<li>Perform check only once, and duplicate the code for each branch. This will increase the code size, but Erlang and Elixir devs usually write small functions, so I don’t except performance to decrease</li>
</ol> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270804" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/35">Post #34</a>
	                </div>
	            </div>
              <div id="likers-container-270804" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270804"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #34"></div>
  </section>
</div>
    <div class="postbit" id="270820" data-post-id="270820">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="hst337" data-post="35" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/41988e/48.png" class="avatar"> hst337:</div>
<blockquote>
<p>So, compiler can optimize the code which uses <code>.</code> and it know that the <code>map</code> is map, however, compiler generates code which performs check <strong>each-time</strong> if it can’t prove that the variable <code>map</code> contains map (and not module).</p>
</blockquote>
</aside>
<p>I believe the issue right now is that <code>map.x</code> means both remote call and map lookup. So I believe it makes it impossible for the code that we generate to be optimized. We started supporting <code>map.x</code> and <code>module.x()</code> as two distinct calls and we emit some warnings when possible but it may be a while until we start emitting smarter (and smaller) code.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270820" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/36">Post #35</a>
	                </div>
	            </div>
              <div id="likers-container-270820" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270820"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #35"></div>
  </section>
</div>
    <div class="postbit" id="270832" data-post-id="270832">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="bjorng" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bjorng/120/13187_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  bjorng
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="34" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>Plaining nested cases is interesting and perhaps even a feature the Erlang/OTP team could be interested in?</p>
</blockquote>
</aside>
<p>What exactly is plaining of nested cases? Can you show an example?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270832" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/37">Post #36</a>
	                </div>
	            </div>
              <div id="likers-container-270832" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270832"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #36"></div>
  </section>
</div>
    <div class="postbit" id="270844" data-post-id="270844">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hst337" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hst337
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<pre data-code-wrap="elixir"><code class="lang-elixir">case x do
  %{y: y} -&gt;
    case y do
      %{z: z} -&gt; {:ok, z}
      _ -&gt; :error
    end
  _ -&gt;
    :error
end
</code></pre>
<p>To</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">case x do
  %{y: %{z: z}} -&gt; {:ok, z}
  _ -&gt; :error
end
</code></pre>
<p>This particular optimization is useless, but flattening of nested cases can reduce amount of code, reduce amount of clauses and help generate more efficient switch instructions</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270844" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/38">Post #37</a>
	                </div>
	            </div>
              <div id="likers-container-270844" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270844"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #37"></div>
  </section>
</div>
    <div class="postbit" id="270863" data-post-id="270863">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oh, I assume in this case this happen a lot in Elixir because of <code>with</code>? In this case, once <code>maybe</code> expressions are fully integrated to Erlang/OTP, I am hoping we can compile to something more efficient.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270863" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/39">Post #38</a>
	                </div>
	            </div>
              <div id="likers-container-270863" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270863"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #38"></div>
  </section>
</div>
    <div class="postbit" id="270878" data-post-id="270878">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="benwilson512" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/120/1457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  benwilson512
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Craft GraphQL APIs in Elixir with Absinthe</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="hst337" data-post="35" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/41988e/48.png" class="avatar"> hst337:</div>
<blockquote>
<p>When one of steps is pure</p>
</blockquote>
</aside>
<p>How is this knowable though? Every one of those functions you listed takes a user supplied function, and the purity of that function is not knowable.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270878" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/40">Post #39</a>
	                </div>
	            </div>
              <div id="likers-container-270878" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270878"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #39"></div>
  </section>
</div>
    <div class="postbit" id="270894" data-post-id="270894">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="bjorng" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bjorng/120/13187_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  bjorng
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="hst337" data-post="38" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/41988e/48.png" class="avatar"> hst337:</div>
<blockquote>
<p>This particular optimization is useless, but flattening of nested cases can reduce amount of code, reduce amount of clauses and help generate more efficient switch instructions</p>
</blockquote>
</aside>
<p>You mean it’s useless because the Erlang compiler will generate the same BEAM code for both examples?</p>
<p>I would be interested in (real-world) examples where the Erlang compiler is unable to do that optimization. If we could improve the Erlang compiler to generate better code for nested cases it would benefit the entire BEAM community.</p>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="39" data-topic="36193">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>In this case, once <code>maybe</code> expressions are fully integrated to Erlang/OTP, I am hoping we can compile to something more efficient.</p>
</blockquote>
</aside>
<p>In Erlang/OTP 26, it sufficient to enable the <code>maybe</code> feature in the compiler. There is no longer any need to enable it in the runtime system too for it to work. We realized that we had to do that so that we could use <code>maybe</code> in OTP code.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270894" data-batch-url="/posts/batch_likers">
                        5
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/enum-fusion/36193/41">Post #40</a>
	                </div>
	            </div>
              <div id="likers-container-270894" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270894"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #40"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/36193/load_more?page=5">Load more posts (3 remaining)</a>
</div></template></turbo-stream>