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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                    <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">
								<aside class="quote no-group" data-username="kip" data-post="11" data-topic="18661">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kip/48/1440_2.png" class="avatar"> kip:</div>
<blockquote>
<p>Are their any anecdotes yet reflecting relative performance of <code>:persistent_term</code> versus functions that bake in data?</p>
</blockquote>
</aside>
<p>Hmm, don’t know, let’s test, I whipped up a simple benchmark between persistent_term, ets, and head dispatch (which is how protocols dispatch), using 1000 trivial entries of ints and 1000 entries of 32-byte binaries, the source:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule BenchDefs do
  def range(:ints), do: 1..1000

  def range(:binaries32),
    do: unquote(Enum.map(1..1000, fn _ -&gt; :crypto.strong_rand_bytes(32) end))
end

defmodule HeadDispatch do
  for i &lt;- [BenchDefs.range(:binaries32), BenchDefs.range(:ints)], j &lt;- i do
    def match(unquote(j)), do: unquote(j)
  end
end

defmodule PersistentTermBench do
  def classifiers(), do: [:ints, :binaries32]

  def time(_), do: 2

  def inputs(cla),
    do: %{
      "First" =&gt; BenchDefs.range(cla) |&gt; Enum.into([]) |&gt; List.last(),
      "Last" =&gt; BenchDefs.range(cla) |&gt; Enum.into([]) |&gt; List.last()
    }

  def setup(cla) do
    Enum.each(BenchDefs.range(cla), &amp;:persistent_term.put(&amp;1, &amp;1))
    tab = :ets.new(PersistentTermBench, [])
    Enum.each(BenchDefs.range(cla), &amp;:ets.insert_new(tab, {&amp;1}))
    tab
  end

  def teardown(_, tab) do
    :ets.delete(tab)
  end

  def actions(_, tab),
    do: %{
      ":persistent_term" =&gt; fn inp -&gt; :persistent_term.get(inp) end,
      ":ets" =&gt; fn inp -&gt; :ets.lookup(tab, inp) end,
      "HeadDispatch" =&gt; fn inp -&gt; HeadDispatch.match(inp) end
    }
end
</code></pre>
<p>And the results:</p>
<pre><code class="lang-plaintext">Benchmarking Classifier: ints
=============================

Operating System: Linux"
CPU Information: AMD Phenom(tm) II X6 1090T Processor
Number of Available Cores: 6
Available memory: 15.67 GB
Elixir 1.7.4
Erlang 21.2

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 2 s
memory time: 2 s
parallel: 1
inputs: First, Last
Estimated total run time: 36 s


Benchmarking :ets with input First...
Benchmarking :ets with input Last...
Benchmarking :persistent_term with input First...
Benchmarking :persistent_term with input Last...
Benchmarking HeadDispatch with input First...
Benchmarking HeadDispatch with input Last...

##### With input First #####
Name                       ips        average  deviation         median         99th %
HeadDispatch           22.21 M      0.0450 μs     ±6.97%      0.0440 μs      0.0540 μs
:persistent_term       15.28 M      0.0655 μs     ±3.23%      0.0650 μs      0.0740 μs
:ets                    8.07 M       0.124 μs   ±172.07%       0.120 μs       0.180 μs

Comparison: 
HeadDispatch           22.21 M
:persistent_term       15.28 M - 1.45x slower
:ets                    8.07 M - 2.75x slower

Memory usage statistics:

Name                Memory usage
HeadDispatch               136 B
:persistent_term           136 B - 1.00x memory usage
:ets                       200 B - 1.47x memory usage

**All measurements for memory usage were the same**

##### With input Last #####
Name                       ips        average  deviation         median         99th %
HeadDispatch           22.38 M      0.0447 μs     ±6.12%      0.0440 μs      0.0530 μs
:persistent_term       15.21 M      0.0658 μs     ±7.30%      0.0650 μs      0.0750 μs
:ets                    8.08 M       0.124 μs   ±143.17%       0.120 μs       0.180 μs

Comparison: 
HeadDispatch           22.38 M
:persistent_term       15.21 M - 1.47x slower
:ets                    8.08 M - 2.77x slower

Memory usage statistics:

Name                Memory usage
HeadDispatch               136 B
:persistent_term           136 B - 1.00x memory usage
:ets                       200 B - 1.47x memory usage

**All measurements for memory usage were the same**

Benchmarking Classifier: binaries32
===================================

Operating System: Linux"
CPU Information: AMD Phenom(tm) II X6 1090T Processor
Number of Available Cores: 6
Available memory: 15.67 GB
Elixir 1.7.4
Erlang 21.2

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 2 s
memory time: 2 s
parallel: 1
inputs: First, Last
Estimated total run time: 36 s


Benchmarking :ets with input First...
Benchmarking :ets with input Last...
Benchmarking :persistent_term with input First...
Benchmarking :persistent_term with input Last...
Benchmarking HeadDispatch with input First...
Benchmarking HeadDispatch with input Last...

##### With input First #####
Name                       ips        average  deviation         median         99th %
HeadDispatch           10.98 M      0.0911 μs   ±271.68%      0.0800 μs       0.180 μs
:persistent_term        8.17 M       0.122 μs   ±240.94%       0.120 μs       0.180 μs
:ets                    4.74 M        0.21 μs    ±85.30%        0.20 μs        0.31 μs

Comparison: 
HeadDispatch           10.98 M
:persistent_term        8.17 M - 1.34x slower
:ets                    4.74 M - 2.32x slower

Memory usage statistics:

Name                Memory usage
HeadDispatch               184 B
:persistent_term           136 B - 0.74x memory usage
:ets                       248 B - 1.35x memory usage

**All measurements for memory usage were the same**

##### With input Last #####
Name                       ips        average  deviation         median         99th %
HeadDispatch           10.86 M      0.0921 μs   ±481.96%      0.0900 μs       0.170 μs
:persistent_term        8.10 M       0.123 μs   ±254.71%       0.120 μs       0.180 μs
:ets                    4.79 M        0.21 μs    ±72.56%        0.20 μs        0.30 μs

Comparison: 
HeadDispatch           10.86 M
:persistent_term        8.10 M - 1.34x slower
:ets                    4.79 M - 2.27x slower

Memory usage statistics:

Name                Memory usage
HeadDispatch               184 B
:persistent_term           136 B - 0.74x memory usage
:ets                       248 B - 1.35x memory usage

**All measurements for memory usage were the same**
</code></pre>
<p>So interned head matchers are still the fastest, barely, followed closely by persistent_term, with ETS over 2 times slower after that.  So keeping protocols as head matchers is still fastest.</p>
<aside class="quote no-group" data-username="kip" data-post="11" data-topic="18661">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kip/48/1440_2.png" class="avatar"> kip:</div>
<blockquote>
<p><code>:persistent_term</code> looks like a possible good approach for storing locale data in my <a href="https://hex.pm/packages/ex_cldr" rel="nofollow">ex_cldr </a> package since its large and static. However it is a fairly complex <code>Map.t()</code> so their would be some penalty to pay in keeping the data as one large map as apposed to the current approach which decomposes the map into different functions.</p>
</blockquote>
</aside>
<p>I’d say keep it as functions in a module.</p>
<aside class="quote no-group" data-username="Qqwy" data-post="12" data-topic="18661">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/qqwy/48/1349_2.png" class="avatar"> Qqwy:</div>
<blockquote>
<p>Would <code>:persistent_term</code> in theory be the proper way in new Erlang versions to build a dispatch-system akin Elixir’s protocols?</p>
</blockquote>
</aside>
<p>Thus no.  <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> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="107916" 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/erlang-21-2-erts-10-2-released/18661/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-107916" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="107916"
                     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 #12"></div>
  </section>
</div>
    <div class="postbit" id="143812" data-post-id="143812">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi there, I created a Hex package to experiment for distributed code compilation within an Elixir cluster which would take away the “pain” of writing: <a href="https://github.com/archan937/clustorage" class="inline-onebox" rel="noopener nofollow ugc">GitHub - archan937/clustorage: Elixir cluster to store and distribute data and functions by code compilation and hot loading done by a designated "loader node" · GitHub</a></p>
<p>I actually started building this with Discord’s FastGlobal package as inspiration.</p>
<p>I’m curious for your thoughts about it <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> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="143812" 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/erlang-21-2-erts-10-2-released/18661/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-143812" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="143812"
                     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 #13"></div>
  </section>
</div>
    <div class="postbit" id="143865" data-post-id="143865">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                    <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>Hmm, interesting style, API seems good.  Since it looks like the functions run on the cluster side, what happens if they crash?  What happens if they crash the entire node?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="143865" 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/erlang-21-2-erts-10-2-released/18661/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-143865" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="143865"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="143918" data-post-id="143918">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Good questions. The package is not build into that extend right now. Fellow alchemists are welcome to contribute <img src="https://forum.elixirforum.com/images/emoji/apple/sweat_smile.png?v=15" title=":sweat_smile:" class="emoji" alt=":sweat_smile:" loading="lazy" width="20" height="20"></p>
<p>At the moment, all I can say is that the designated loader node will crash first if the compilation is corrupt.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="143918" 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/erlang-21-2-erts-10-2-released/18661/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-143918" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="143918"
                     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>