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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="fireproofsocks" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fireproofsocks/120/7669_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  fireproofsocks
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I tried this (building off of the previous performant solution):</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    index_file
    |&gt; stream_file()
    |&gt; Task.async_stream(
      fn line -&gt;
        path = :lists.droplast(line)
        {:ok, contents} = :prim_file.read_file(path)
        {:ok, %{"paths" =&gt; txt_paths}} = Jason.decode(contents)
        txt_paths
        []
      end,
      max_concurrency: 10,
      ordered: false
    )
    |&gt; Stream.flat_map(fn {:ok, results} -&gt; results end)
    |&gt; Task.async_stream(
      fn path -&gt;
        match?({:ok, _}, :prim_file.read_file_info(path))
      end,
      max_concurrency: 10,
      ordered: false
    )
    |&gt; Stream.run()
</code></pre>
<p>I streamed the file with this code (I think I’m probably reinventing wheels here, but it was educational):</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  def stream_file(input_file) do
    Stream.resource(
      fn -&gt;
        {:ok, file} = :file.open(input_file, [:raw, :read, read_ahead: 8192])
        file
      end,
      fn file -&gt;
        case :file.read_line(file) do
          {:ok, line} -&gt;
            {[line], file}

          :eof -&gt;
            {:halt, file}
        end
      end,
      fn file -&gt; :file.close(file) end
    )
  end
</code></pre>
<p>This performed more or less the same as the other solutions.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="280317" 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/elixir-vs-python-performance-benchmarking/54260/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-280317" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="280317"
                     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 #21"></div>
  </section>
</div>
    <div class="postbit" id="280384" data-post-id="280384">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dogweather" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dogweather/120/1906_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dogweather
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Python has had a lot of speed optimization go into it over the years. I’m not too surprised that a first solution turned out to be pretty good.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="280384" 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/elixir-vs-python-performance-benchmarking/54260/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-280384" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="280384"
                     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 #22"></div>
  </section>
</div>
    <div class="postbit" id="280742" data-post-id="280742">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cro" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cro/120/1992_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cro
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="dogweather" data-post="23" data-topic="54260">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dogweather/48/1906_2.png" class="avatar"> dogweather:</div>
<blockquote>
<p>Python has had a lot of speed optimization go into it over the years.</p>
</blockquote>
</aside>
<p>Yeah, like Java.  We did a PoC at work and “bare” Java (no Spring, Hibernate, or anything but the bare minimum for external libraries) blew away Elixir, Python, and Go, and came in second only to C.</p>
<p>For our use case Elixir was faster than Python.  However, one thing came to light in our PoC that was interesting–Python’s concurrency story is still not great.  Async/await code is super hard to reason about and debug.  There is very little visibility into the event loop in Python async code, and async code tends to proliferate in your codebase since you can’t call <code>await</code> from a non <code>async</code> function.  So when you need to call a coroutine with <code>await</code> the calling function must become <code>async</code>…which means it’s calling function will need to <code>await</code> it and become <code>async</code>.  There are ways around this but they are non-obvious and make your code complex.</p>
<p>The Elixir/BEAM approach is so, so much better.  Not that it is a silver bullet for complex systems, but if you are writing a large scale system that depends heavily on concurrency for performance, I would choose Elixir over Python.</p>
<p>That’s not even getting into the additional DX issues–introspectability, observability, multi-node deployments, the list goes on.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="280742" data-batch-url="/posts/batch_likers">
                        7
                      </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/elixir-vs-python-performance-benchmarking/54260/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-280742" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="280742"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>