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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oh nice, some more good code to read!</p>
<p>Well now that you use your custom storage implementation, it’s not necessary to have special encoding for keys, right? As far as I can see in the Olivine code, it uses <code>:gb_trees</code> for index structure with custom <code>find_page_for_key</code> implementation which looks for key with the default erlang term ordering.</p>
<p>I am also experimenting with storage stuff and I am currently writing a very simple and minimal LSM implementation to try out as a Bedrock backend.</p>
<p><code>@type t :: t()</code> rocks btw <img src="https://forum.elixirforum.com/images/emoji/apple/laughing.png?v=15" title=":laughing:" class="emoji" alt=":laughing:" 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="373001" 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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-373001" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373001"
                     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="373206" data-post-id="373206">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Asd" data-post="32" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/c68b51/48.png" class="avatar"> Asd:</div>
<blockquote>
<p>I am currently writing a very simple and minimal LSM implementation</p>
</blockquote>
</aside>
<p>Please do share when ready, I’ve been strongly considering writing an Elixir LSM as well <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>
<aside class="quote no-group" data-username="Asd" data-post="32" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/c68b51/48.png" class="avatar"> Asd:</div>
<blockquote>
<p>Well now that you use your custom storage implementation, it’s not necessary to have special encoding for keys, right?</p>
</blockquote>
</aside>
<p>Another nice thing about using binaries is that, as I understand it, the BEAM will just keep slicing up the refcounted binary from the page load without any coping.</p>
<p>Imagine you have an LSM. If you have to decode the keys to binary search the index/data blocks all of a sudden you’re copying a bunch of memory and creating a bunch of terms that could have just been binary slices. This is not free.</p>
<p>The same would be true when binary searching a Btree page.</p>
<p>So even if you want term order I still think it would be better to use an encoding which sorts lexicographically in binary form.</p>
<p>I think I will be taking this approach in my own work so if you have a dissenting argument here I would of course very much like to hear it!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373206" 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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-373206" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373206"
                     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="373210" data-post-id="373210">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jallum" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jallum/120/38850_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jallum
                    <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="garrison" data-post="33" data-topic="72038" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>Another nice thing about using binaries is that, as I understand it, the BEAM will just keep slicing up the refcounted binary from the page load without any coping.</p>
</blockquote>
</aside>
<p>Slices are <em>great</em> for temporary work, but the memory bloat can be more permanent. The slice retains a reference to the underlying binary and there can be significant amounts of memory that are accidentally / quietly retained. For example, you read in a 10mb chunk from somewhere, and slice out one 10 byte value to keep. As long as there’s a reference to the 10 byte value, the whole 10mb sticks around, even if you’ve discarded all references to the 10mb chunk. You can sever this linkage with an explicit <code>:binary.copy</code>, though. <code>:binary.referenced_byte_size</code> can tell you more about this, too. There are a bunch of fun toys in:</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://www.erlang.org/docs/28/apps/stdlib/binary.html#functions">
  <header class="source">

      <a href="https://www.erlang.org/docs/28/apps/stdlib/binary.html#functions" target="_blank" rel="noopener nofollow">erlang.org</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://www.erlang.org/docs/28/apps/stdlib/binary.html#functions" target="_blank" rel="noopener nofollow">Pos - binary — OTP 29.0.2 (stdlib 8.0.1)</a></h3>

  <p>Library for handling binary data.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373210" data-batch-url="/posts/batch_likers">
                        3
                      </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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/34">Post #33</a>
	                </div>
	            </div>
              <div id="likers-container-373210" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373210"
                     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="373211" data-post-id="373211">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This is useful info, thanks.</p>
<p>In the case of a storage engine you would only retain the page during a given query (only during the binary search, even) so I think what I said remains correct. I guess you would definitely want to copy out any binaries that you intend to <em>return</em>, though.</p>
<p>Is there any mechanism for the VM to recognize that it’s holding on to a huge binary for a small slice? I just assumed it would figure that out on its own tbh.</p>
<p>Also, tangential, but does anyone know how refcounted binaries interact with ets? Specifically, if you store a binary in an ets table is it copied?</p>
<p>(Nice work on the release, btw)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373211" 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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/35">Post #34</a>
	                </div>
	            </div>
              <div id="likers-container-373211" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373211"
                     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="373215" data-post-id="373215">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jallum" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jallum/120/38850_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jallum
                    <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="garrison" data-post="35" data-topic="72038" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>This is useful info, thanks.</p>
<p>In the case of a storage engine you would only retain the page during a given query (only during the binary search, even) so I think what I said remains correct. I guess you would definitely want to copy out any binaries that you intend to <em>return</em>, though.</p>
</blockquote>
</aside>
<p><em>Just so</em>. Things destined for the network or disk might not matter, but things handed back to other processes (with their own arbitrary lifetimes) will <em>definitely</em> cause you issues with unexpected retains. My understanding is that <code>:binary.copy</code> only actually does anything if the parameter is a slice – it won’t duplicate things unnecessarily, and so it’s okay to use it defensively “at the exits.”</p>
<aside class="quote no-group" data-username="garrison" data-post="35" data-topic="72038" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>Is there any mechanism for the VM to recognize that it’s holding on to a huge binary for a small slice? I just assumed it would figure that out on its own tbh.</p>
</blockquote>
</aside>
<p>Not that i’m aware of. We’re just expected to manage this stuff.</p>
<aside class="quote no-group" data-username="garrison" data-post="35" data-topic="72038" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>Also, tangential, but does anyone know how refcounted binaries interact with ets? Specifically, if you store a binary in an ets table is it copied?</p>
</blockquote>
</aside>
<p>Binaries (&gt;= 64 bytes) are never copied. Everything else <em>will be</em> if the :ets table is accessed from another process.</p>
<p>In general, <em>anything</em> other than a “large” binary is <strong>copied</strong> when crossing a process boundary, whether it’s an :ets read, or a message send, etc. For :ets reads, the reader “pays the toll” and will recursively copy whatever is read into it’s own space and for message sends, the sender “pays the toll” of copying the message into the receiver’s space.</p>
<p>This is why it can be faster to pass large binaries around between processes instead of large structures (and why Bedrock now binary-encodes transactions early and passes <em>those</em> around).</p>
<aside class="quote no-group" data-username="garrison" data-post="35" data-topic="72038" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>(Nice work on the release, btw)</p>
</blockquote>
</aside>
<p>Thank you! On deck next is a full slate of atomic operations, control over the read/write conflicts sets and other refinements necessary to support a fdb-style high-contention-allocator and directory layer. Stay tuned.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373215" 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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/36">Post #35</a>
	                </div>
	            </div>
              <div id="likers-container-373215" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373215"
                     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="373217" data-post-id="373217">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="jallum" data-post="36" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jallum/48/38850_2.png" class="avatar"> jallum:</div>
<blockquote>
<p>and why Bedrock now binary-encodes transactions early and passes <em>those</em> around</p>
</blockquote>
</aside>
<p>Mm, I have thought about doing this. Especially since it may be possible to encode things in such a way that the batch fragment destined for a particular storage server can essentially travel <em>through</em> the TLog (and WAL on disk) without ever being decoded.</p>
<p>In practice I think the FDB tagging design (randomly assigning tags when the storage servers’ tlogs overlap) makes this messy. Frankly this design is bad and I don’t know what they were thinking. I guess it just pre-dates the idea of copysets.</p>
<p>It would be much better to create TLog teams as copysets and assign storage tags at the team level. When I was reading through your code I think that might even be what you did, in which case congrats for dodging that mess!</p>
<p>It’s a one-way door, though. Once you go full copyset you can only move data at the team level, so you can never go back. Meaning small deployments have to use copysets too even when it’s less than ideal. I think I’m just going to commit to that design, though. Spilling the TLogs without team-level tags is just <em>so messy</em> and it’s keeping me up at night.</p>
<aside class="quote no-group" data-username="jallum" data-post="36" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jallum/48/38850_2.png" class="avatar"> jallum:</div>
<blockquote>
<p>Things destined for the network or disk might not matter</p>
</blockquote>
</aside>
<p>I considered this, but if you want the DB to work embedded then you have <em>no control</em> over whether it’s headed for the network or not because you don’t know if the read is local to the node. So copying it is!</p>
<p>In practice copying the returned keys/values out of the page is exactly what you would do in a “normal” (non-Erlang) implementation anyway so it’s no big deal.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373217" 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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/37">Post #36</a>
	                </div>
	            </div>
              <div id="likers-container-373217" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373217"
                     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="373224" data-post-id="373224">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="garrison" data-post="33" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>Imagine you have an LSM. If you have to decode the keys to binary search the index/data blocks all of a sudden you’re copying a bunch of memory and creating a bunch of terms that could have just been binary slices. This is not free.</p>
</blockquote>
</aside>
<ol>
<li>This is a premature optimization. Let’s do the terms-as-keys and compare the performance. First make it working, then beautiful, then fast and so on.</li>
<li>This is a false dilemma. We can have 0-copy for binaries and simple tuples while having arbitrary terms-as-keys at the same time, because if we have string keys or tuple of strings keys, we can instantiate them with <code>binary_to_term</code> (or implement own version of <code>binary_to_term</code> for strings with fallback to <code>:erlang.binary_to_term</code>) without copying as well.</li>
<li>This is a more broader point than just this discussion about keys. If I wanted the most efficient, well tested and production ready FoundationDB in Elixir, I’d just use vanilla Foundation DB with NIFs interface. So, if someone is ever going to use Bedrock, it will be not because of it’s performance, but it will be more of it’s interoperability with Elixir, ability to work with it the Elixir way, introspect it in Elixir and so on. This is just my personal point, and I will understand if you think the other way about this project</li>
</ol>
<p>P.S. I keep saying “we” when proposing solutions, but I am not in your team and it looks awkward (for me at least), and that’s just my poor English, please don’t mind it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373224" 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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/38">Post #37</a>
	                </div>
	            </div>
              <div id="likers-container-373224" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373224"
                     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="373229" data-post-id="373229">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Asd" data-post="38" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/c68b51/48.png" class="avatar"> Asd:</div>
<blockquote>
<p>This is a premature optimization</p>
</blockquote>
</aside>
<p>The threshold for “premature” is IMO much higher for a storage engine. I have been debating (with myself) whether it’s even possible to write a useful storage engine in Elixir, and one of the biggest problems is a lack of control over memory allocation.</p>
<p>I’ve been leaning towards LSM in part because the design necessitates copying where a Btree would benefit greatly from in-place mutation of pages (in memory not on disk) which seems more natural in a functional language. Still, there are challenges.</p>
<p>Being able to binary search the blocks without decoding (and therefore copying) the keys seems to me like it would be a meaningful advantage. But of course some microbenchmarks could show it matters less than I think!</p>
<aside class="quote no-group" data-username="Asd" data-post="38" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/c68b51/48.png" class="avatar"> Asd:</div>
<blockquote>
<p>We can have 0-copy for binaries and simple tuples while having arbitrary terms-as-keys at the same time, because if we have string keys or tuple of strings keys, we can instantiate them with <code>binary_to_term</code></p>
</blockquote>
</aside>
<p>I don’t see how this would work because they have to be comparable (<code>bin_a &lt; bin_b</code>) in encoded form to avoid decoding. But maybe I am misunderstanding you?</p>
<aside class="quote no-group" data-username="Asd" data-post="38" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/c68b51/48.png" class="avatar"> Asd:</div>
<blockquote>
<p>This is a more broader point than just this discussion about keys. If I wanted the most efficient, well tested and production ready FoundationDB in Elixir, I’d just use vanilla Foundation DB with NIFs interface</p>
</blockquote>
</aside>
<p>This is entirely reasonable. I personally have a specific set of goals which preclude the use of FDB, but Bedrock (while similar in some ways) is not my project and likely has different goals. That’s not up to me to comment on.</p>
<p>What other functionality do you think would benefit from using terms down to the storage layer? Introspection/debugging is a good example.</p>
<aside class="quote no-group" data-username="Asd" data-post="38" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/c68b51/48.png" class="avatar"> Asd:</div>
<blockquote>
<p>P.S. I keep saying “we” when proposing solutions, but I am not in your team and it looks awkward (for me at least), and that’s just my poor English, please don’t mind it.</p>
</blockquote>
</aside>
<p>This is normal in English; native speakers do this all the time. It doesn’t look awkward to me.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373229" 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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/39">Post #38</a>
	                </div>
	            </div>
              <div id="likers-container-373229" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373229"
                     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="373256" data-post-id="373256">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="garrison" data-post="39" data-topic="72038">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>I don’t see how this would work because they have to be comparable (<code>bin_a &lt; bin_b</code>) in encoded form to avoid decoding. But maybe I am misunderstanding you?</p>
</blockquote>
</aside>
<p>For example, I read from binary some encoded with <code>:erlang.term_to_binary</code> string. It will look like <code>&lt;&lt;131, 109, size :: 32, string :: binary-size(size)&gt;&gt;</code>. I can’t compare encoded (because it will compare by size first), but I can use this pattern to extract the string and then compare it without any copying since it will be just a reference sub binary.</p>
<p>This way we leave the decision to optimize the key for fast comparison (or not) to the user. If user wants to have really fast comparison, they can implement their own encoding and just write strings into the storage</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373256" 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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/40">Post #39</a>
	                </div>
	            </div>
              <div id="likers-container-373256" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373256"
                     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="373297" data-post-id="373297">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I understand now, thanks for clarifying. I don’t know the <code>term_to_binary</code> encodings but if it’s easy to pull the raw binary out with a quick pattern match as you suggest then I agree this could be a reasonable approach.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373297" 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/bedrock-a-scaleable-distributed-key-value-database-with-better-than-acid-guarantees/72038/41">Post #40</a>
	                </div>
	            </div>
              <div id="likers-container-373297" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373297"
                     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/72038/load_more?page=5">Load more posts (27 remaining)</a>
</div></template></turbo-stream>