<div dir="ltr"><div>Sounds like mutation of persistent terms has implications(across the runtime, affecting everybody, even those who are not involved). For as long as it is mostly read-only, it should be fine as the docs also notes</div><div> </div><div><b>Term lookup (using <span class="gmail-bold_code gmail-bc-17"><a href="https://erlang.org/doc/man/persistent_term.html#get-1"><span class="gmail-code">get/1</span></a></span>), is done in constant time
    and without taking any locks, and the term is not
    copied to the heap (as is the case with terms stored in ETS
    tables).</b><br><div><br></div><div>It's the writes that should be cautiously and preferably controlled for the most optimal usage.</div><div><br></div><div>Regards</div><div>Nalin Ranjan</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 6, 2020 at 9:07 PM Zsolt Laky <<a href="mailto:zsolt.laky@lamardan.com">zsolt.laky@lamardan.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Hi,<div><br></div><div>You migh take a look at <a href="http://blog.erlang.org/persistent_term/" target="_blank">http://blog.erlang.org/persistent_term/</a></div><div><br></div><div>Excellent article by Lukas, answered a lot of questions.</div><div><br></div><div>Kind regards,</div><div>Zsolt<br><br><div dir="ltr">Sent from my iPad</div><div dir="ltr"><br><blockquote type="cite">On 2020. Dec 6., at 15:30, Richard O'Keefe <<a href="mailto:raoknz@gmail.com" target="_blank">raoknz@gmail.com</a>> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">Thanks for that advice about persistent_term.</div><div class="gmail_default" style="font-family:monospace,monospace">From the documentation,</div><div class="gmail_default" style="font-family:monospace,monospace"><quote><br></div><div class="gmail_default" style="font-family:monospace,monospace">When a persistent term is updated or deleted, a global garbage collection pass is run to scan all processes for the deleted term, and to copy it into each process that still uses it.</div><div class="gmail_default" style="font-family:monospace,monospace"></quote></div><div class="gmail_default" style="font-family:monospace,monospace">Do I understand correctly that if three processes refer</div><div class="gmail_default" style="font-family:monospace,monospace">to a persistent-term, and one of them deletes it, it</div><div class="gmail_default" style="font-family:monospace,monospace">will be copied into both of the other processes, thus</div><div class="gmail_default" style="font-family:monospace,monospace">INCREASING the amount of memory used?</div><div class="gmail_default" style="font-family:monospace,monospace">This is sufficiently counter-intuitive that I am not</div><div class="gmail_default" style="font-family:monospace,monospace">sure I would dare to use this feature.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Do I further understand correctly that *adding* a new</div><div class="gmail_default" style="font-family:monospace,monospace">persistent-term does NOT force garbage collection?</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 7 Dec 2020 at 00:49, Nalin Ranjan <<a href="mailto:ranjanified@gmail.com" target="_blank">ranjanified@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">It has the potential to trigger Global GC, and can affect responsiveness as per the docs. <div><br></div><div><a href="https://erlang.org/doc/man/persistent_term.html" target="_blank">https://erlang.org/doc/man/persistent_term.html</a> <br></div><div><br></div><div>Regards</div><div>Nalin Ranjan</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 6, 2020 at 5:16 AM Frank Muller <<a href="mailto:frank.muller.erl@gmail.com" target="_blank">frank.muller.erl@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="word-spacing:1px;border-color:rgb(49,49,49);color:rgb(49,49,49)">Hi guys,</span><br style="color:rgb(212,212,213);font-family:-apple-system,HelveticaNeue;word-spacing:1px"><br style="color:rgb(212,212,213);font-family:-apple-system,HelveticaNeue;word-spacing:1px"><span style="word-spacing:1px;border-color:rgb(49,49,49);color:rgb(49,49,49)">At work, we cache about 5.3 million entries in ETS. The system works perfectly, no issue so far (many years).</span><div dir="auto"><font style="border-color:rgb(49,49,49);color:rgb(49,49,49)"><br style="color:rgb(212,212,213);word-spacing:1px"></font><span style="word-spacing:1px;border-color:rgb(49,49,49);color:rgb(49,49,49)">During a brainstorming session, a colleague suggested to switch to persistent_term instead to avoid ETS term copying.</span><br style="color:rgb(212,212,213);font-family:-apple-system,HelveticaNeue;word-spacing:1px"><br style="color:rgb(212,212,213);font-family:-apple-system,HelveticaNeue;word-spacing:1px"><span style="word-spacing:1px;border-color:rgb(49,49,49);color:rgb(49,49,49)">Pretty simple: we check if the Key exists in persistent_term. If yes, we are done. If not, we get it from ETS, move it to persistent_term and send it back to the caller.</span></div><div style="background-color:rgba(0,0,0,0);border-color:rgb(255,255,255)" dir="auto"><font style="border-color:rgb(49,49,49);color:rgb(49,49,49)"><br style="color:rgb(212,212,213);word-spacing:1px"></font><span style="word-spacing:1px;border-color:rgb(49,49,49);color:rgb(49,49,49)">Question: is there any limitation(s) on persistent_term usage? Stated otherwise, can we create 5.3 million persistent_term <K,V>?</span><br style="color:rgb(212,212,213);font-family:-apple-system,HelveticaNeue;word-spacing:1px"><br style="color:rgb(212,212,213);font-family:-apple-system,HelveticaNeue;word-spacing:1px"><span style="word-spacing:1px;border-color:rgb(49,49,49);color:rgb(49,49,49)">Any suggestion/idea/thought is very welcome.</span><br style="color:rgb(212,212,213);font-family:-apple-system,HelveticaNeue;word-spacing:1px"><br style="color:rgb(212,212,213);font-family:-apple-system,HelveticaNeue;word-spacing:1px"><span style="word-spacing:1px;border-color:rgb(49,49,49);color:rgb(49,49,49)">/Frank</span></div>
</blockquote></div>
</blockquote></div>
</div></blockquote></div></div></blockquote></div>