Skip to content

Commit

Permalink
Automated publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Github Actions committed Dec 30, 2023
1 parent c45fde1 commit f1a33bf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion blog/2023-12-30-fast-string/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<span class="line"><span style="color:#f92672">---------------------------------^^</span></span>
<span class="line"><span style="color:#88846f"> /* Actual capacity data. */</span><span style="color:#f8f8f2"> </span><span style="color:#f92672">|||</span></span>
<span class="line"><span style="color:#88846f"> /* Is it large? */</span><span style="color:#f8f8f2"> </span><span style="color:#f92672">||</span></span>
<span class="line"><span style="color:#88846f"> /* Is it medium? */</span><span style="color:#f8f8f2"> </span><span style="color:#f92672">|</span></span></code></pre><p>For a small string, both of those flag bits are 0. This is important and it's the final piece to a puzzle: where do we store the size, for small strings? Well, we store it in the remaining 6 bits of capacity data. But we don't just store the size, oh no. We store the <em>remaining capacity</em> (max_size - size). This lovely treat allows us to use that final byte as the null terminator when the string is full, since the two flag bits will be 0 and the remaining capacity will be 0, thus the byte will be 0.<p>This means folly's string allows for 23 bytes of small string data in a 24 byte string. That's <code>23:34 = 0.958</code>, compared to the previous <code>15:32 = 0.469</code>. Our string is 24 bytes, compared to previous 32 bytes, too! A very impressive design.<h2>Empty member optimization</h2><p>There's a trick which all three of the string classes use called <a href="https://www.cantrip.org/emptyopt.html">empty member optimization</a> and I'll explain it because it's another example of how crazy C++ is. In C++, an empty struct can't have the size of 0. It generally has the size of 1. This is important for addressing, as I'll show here.<pre class="shiki"style="background-color:#272822"><code><span class="line"><span style="color:#66d9ef;font-style:italic">struct</span><span style="color:#f8f8f2"> </span><span style="color:#a6e22e">empty</span></span>
<span class="line"><span style="color:#88846f"> /* Is it medium? */</span><span style="color:#f8f8f2"> </span><span style="color:#f92672">|</span></span></code></pre><p>For a small string, both of those flag bits are 0. This is important and it's the final piece to a puzzle: where do we store the size, for small strings? Well, we store it in the remaining 6 bits of capacity data. But we don't just store the size, oh no. We store the <em>remaining capacity</em> (max_size - size). This lovely treat allows us to use that final byte as the null terminator when the string is full, since the two flag bits will be 0 and the remaining capacity will be 0, thus the byte will be 0.<p>This means folly's string allows for 23 bytes of small string data in a 24 byte string. That's <code>23:24 = 0.958</code>, compared to the previous <code>15:32 = 0.469</code>. Our string is 24 bytes, compared to previous 32 bytes, too! A very impressive design.<h2>Empty member optimization</h2><p>There's a trick which all three of the string classes use called <a href="https://www.cantrip.org/emptyopt.html">empty member optimization</a> and I'll explain it because it's another example of how crazy C++ is. In C++, an empty struct can't have the size of 0. It generally has the size of 1. This is important for addressing, as I'll show here.<pre class="shiki"style="background-color:#272822"><code><span class="line"><span style="color:#66d9ef;font-style:italic">struct</span><span style="color:#f8f8f2"> </span><span style="color:#a6e22e">empty</span></span>
<span class="line"><span style="color:#f8f8f2">{ };</span></span>
<span class="line"></span>
<span class="line"><span style="color:#66d9ef;font-style:italic">struct</span><span style="color:#f8f8f2"> </span><span style="color:#a6e22e">foo</span></span>
Expand Down
2 changes: 1 addition & 1 deletion blog/feed.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<feed xmlns="http://www.w3.org/2005/Atom"><link href="https://jank-lang.org/blog/feed.xml" rel="self" type="application/atom+xml" /><link href="https://jank-lang.org/blog/" rel="alternate" type="text/html" /><updated>2023-12-30T21:14:01.778401081Z</updated><title>jank blog</title><id>https://jank-lang.org/blog/</id><entry><title type="html">jank&apos;s new persistent string is fast</title><link href="https://jank-lang.org/blog/2023-12-30-fast-string" rel="alternate" title="jank&apos;s new persistent string is fast" type="text/html" /><published>2023-12-30T00:00:00Z</published><updated>2023-12-30T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-12-30-fast-string</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;One thing I&amp;apos;ve been meaning to do is build a custom string class for jank. I had some time, during the holidays, between wrapping up this quarter&amp;apos;s work and starting on next quarter&amp;apos;s, so I decided to see if I could beat both &lt;code&gt;std::string&lt;/code&gt; and &lt;code&gt;folly::fbstring&lt;/code&gt;, in terms of performance. After all, if we&amp;apos;re gonna make a string class, it&amp;apos;ll need to be fast. :)&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Load all the modules!</title><link href="https://jank-lang.org/blog/2023-12-17-module-loading" rel="alternate" title="jank development update - Load all the modules!" type="text/html" /><published>2023-12-17T00:00:00Z</published><updated>2023-12-17T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-12-17-module-loading</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;I&amp;apos;ve been quiet for the past couple of months, finishing up this work on jank&amp;apos;s module loading, class path handling, aliasing, and var referring. Along the way, I ran into some very interesting bugs and we&amp;apos;re in for a treat of technical detail in this holiday edition of jank development updates! A warm shout out to my &lt;a href=&quot;https://github.com/sponsors/jeaye&quot;&gt;Github sponsors&lt;/a&gt; and &lt;a href=&quot;https://www.clojuriststogether.org/&quot;&gt;Clojurists Together&lt;/a&gt; for sponsoring this work.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Module loading</title><link href="https://jank-lang.org/blog/2023-10-14-module-loading" rel="alternate" title="jank development update - Module loading" type="text/html" /><published>2023-10-14T00:00:00Z</published><updated>2023-10-14T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-10-14-module-loading</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;For the past month and a half, I&amp;apos;ve been building out jank&amp;apos;s support for &lt;code&gt;clojure.core/require&lt;/code&gt;, including everything from class path handling to compiling jank files to intermediate code written to the filesystem. This is a half-way report for the quarter. As a warm note, my work on jank this quarter is being sponsored by &lt;a href=&quot;https://www.clojuriststogether.org/&quot;&gt;Clojurists Together&lt;/a&gt;.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Object model results</title><link href="https://jank-lang.org/blog/2023-08-26-object-model" rel="alternate" title="jank development update - Object model results" type="text/html" /><published>2023-08-26T00:00:00Z</published><updated>2023-08-26T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-08-26-object-model</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;As summer draws to a close, in the Pacific Northwest, so too does my term of sponsored work focused on a faster object model for jank. Thanks so much to &lt;a href=&quot;https://www.clojuriststogether.org/&quot;&gt;Clojurists Together&lt;/a&gt; for funding jank&amp;apos;s development. The past quarter has been quite successful and I&amp;apos;m excited to share the results.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - A faster object model</title><link href="https://jank-lang.org/blog/2023-07-08-object-model" rel="alternate" title="jank development update - A faster object model" type="text/html" /><published>2023-07-08T00:00:00Z</published><updated>2023-07-08T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-07-08-object-model</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;This quarter, my work on jank is being sponsored by &lt;a href=&quot;https://www.clojuriststogether.org/&quot;&gt;Clojurists Together&lt;/a&gt;. The terms of the work are to research a new object model for jank, with the goal of making jank code faster across the board. This is a half-way report and I&amp;apos;m excited to share my results!&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Optimizing a ray tracer</title><link href="https://jank-lang.org/blog/2023-04-07-ray-tracing" rel="alternate" title="jank development update - Optimizing a ray tracer" type="text/html" /><published>2023-04-07T00:00:00Z</published><updated>2023-04-07T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-04-07-ray-tracing</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;After the &lt;a href=&quot;/blog/2023-01-13-optimizing-sequences&quot;&gt;last post&lt;/a&gt;, which focused on optimizing jank&amp;apos;s sequences, I wanted to get jank running a ray tracer I had previously written in Clojure. In this post, I document what was required to start ray tracing in jank and, more importantly, how I chased down the run time in a fierce battle with Clojure&amp;apos;s performance.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Optimizing sequences</title><link href="https://jank-lang.org/blog/2023-01-13-optimizing-sequences" rel="alternate" title="jank development update - Optimizing sequences" type="text/html" /><published>2023-01-13T00:00:00Z</published><updated>2023-01-13T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-01-13-optimizing-sequences</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;In this episode of jank&amp;apos;s development updates, we follow an exciting few weekends as I was digging deep into Clojure&amp;apos;s sequence implementation, building jank&amp;apos;s equivalent, and then benchmarking and profiling in a dizzying race to the bottom.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Lots of new changes</title><link href="https://jank-lang.org/blog/2022-12-08-progress-update" rel="alternate" title="jank development update - Lots of new changes" type="text/html" /><published>2022-12-08T00:00:00Z</published><updated>2022-12-08T00:00:00Z</updated><id>https://jank-lang.org/blog/2022-12-08-progress-update</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;I was previously giving updates only in the &lt;a href=&quot;https://clojurians.slack.com/archives/C03SRH97FDK&quot;&gt;#jank&lt;/a&gt; Slack channel, but some of these are getting large enough to warrant more prose. Thus, happily, I can announce that jank has a new blog and I have a &lt;i&gt;lot&lt;/i&gt; of new progress to report! Let&amp;apos;s get into the details.&lt;/p&gt;</summary></entry></feed>
<feed xmlns="http://www.w3.org/2005/Atom"><link href="https://jank-lang.org/blog/feed.xml" rel="self" type="application/atom+xml" /><link href="https://jank-lang.org/blog/" rel="alternate" type="text/html" /><updated>2023-12-30T22:08:40.115640319Z</updated><title>jank blog</title><id>https://jank-lang.org/blog/</id><entry><title type="html">jank&apos;s new persistent string is fast</title><link href="https://jank-lang.org/blog/2023-12-30-fast-string" rel="alternate" title="jank&apos;s new persistent string is fast" type="text/html" /><published>2023-12-30T00:00:00Z</published><updated>2023-12-30T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-12-30-fast-string</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;One thing I&amp;apos;ve been meaning to do is build a custom string class for jank. I had some time, during the holidays, between wrapping up this quarter&amp;apos;s work and starting on next quarter&amp;apos;s, so I decided to see if I could beat both &lt;code&gt;std::string&lt;/code&gt; and &lt;code&gt;folly::fbstring&lt;/code&gt;, in terms of performance. After all, if we&amp;apos;re gonna make a string class, it&amp;apos;ll need to be fast. :)&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Load all the modules!</title><link href="https://jank-lang.org/blog/2023-12-17-module-loading" rel="alternate" title="jank development update - Load all the modules!" type="text/html" /><published>2023-12-17T00:00:00Z</published><updated>2023-12-17T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-12-17-module-loading</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;I&amp;apos;ve been quiet for the past couple of months, finishing up this work on jank&amp;apos;s module loading, class path handling, aliasing, and var referring. Along the way, I ran into some very interesting bugs and we&amp;apos;re in for a treat of technical detail in this holiday edition of jank development updates! A warm shout out to my &lt;a href=&quot;https://github.com/sponsors/jeaye&quot;&gt;Github sponsors&lt;/a&gt; and &lt;a href=&quot;https://www.clojuriststogether.org/&quot;&gt;Clojurists Together&lt;/a&gt; for sponsoring this work.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Module loading</title><link href="https://jank-lang.org/blog/2023-10-14-module-loading" rel="alternate" title="jank development update - Module loading" type="text/html" /><published>2023-10-14T00:00:00Z</published><updated>2023-10-14T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-10-14-module-loading</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;For the past month and a half, I&amp;apos;ve been building out jank&amp;apos;s support for &lt;code&gt;clojure.core/require&lt;/code&gt;, including everything from class path handling to compiling jank files to intermediate code written to the filesystem. This is a half-way report for the quarter. As a warm note, my work on jank this quarter is being sponsored by &lt;a href=&quot;https://www.clojuriststogether.org/&quot;&gt;Clojurists Together&lt;/a&gt;.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Object model results</title><link href="https://jank-lang.org/blog/2023-08-26-object-model" rel="alternate" title="jank development update - Object model results" type="text/html" /><published>2023-08-26T00:00:00Z</published><updated>2023-08-26T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-08-26-object-model</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;As summer draws to a close, in the Pacific Northwest, so too does my term of sponsored work focused on a faster object model for jank. Thanks so much to &lt;a href=&quot;https://www.clojuriststogether.org/&quot;&gt;Clojurists Together&lt;/a&gt; for funding jank&amp;apos;s development. The past quarter has been quite successful and I&amp;apos;m excited to share the results.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - A faster object model</title><link href="https://jank-lang.org/blog/2023-07-08-object-model" rel="alternate" title="jank development update - A faster object model" type="text/html" /><published>2023-07-08T00:00:00Z</published><updated>2023-07-08T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-07-08-object-model</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;This quarter, my work on jank is being sponsored by &lt;a href=&quot;https://www.clojuriststogether.org/&quot;&gt;Clojurists Together&lt;/a&gt;. The terms of the work are to research a new object model for jank, with the goal of making jank code faster across the board. This is a half-way report and I&amp;apos;m excited to share my results!&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Optimizing a ray tracer</title><link href="https://jank-lang.org/blog/2023-04-07-ray-tracing" rel="alternate" title="jank development update - Optimizing a ray tracer" type="text/html" /><published>2023-04-07T00:00:00Z</published><updated>2023-04-07T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-04-07-ray-tracing</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;After the &lt;a href=&quot;/blog/2023-01-13-optimizing-sequences&quot;&gt;last post&lt;/a&gt;, which focused on optimizing jank&amp;apos;s sequences, I wanted to get jank running a ray tracer I had previously written in Clojure. In this post, I document what was required to start ray tracing in jank and, more importantly, how I chased down the run time in a fierce battle with Clojure&amp;apos;s performance.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Optimizing sequences</title><link href="https://jank-lang.org/blog/2023-01-13-optimizing-sequences" rel="alternate" title="jank development update - Optimizing sequences" type="text/html" /><published>2023-01-13T00:00:00Z</published><updated>2023-01-13T00:00:00Z</updated><id>https://jank-lang.org/blog/2023-01-13-optimizing-sequences</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;In this episode of jank&amp;apos;s development updates, we follow an exciting few weekends as I was digging deep into Clojure&amp;apos;s sequence implementation, building jank&amp;apos;s equivalent, and then benchmarking and profiling in a dizzying race to the bottom.&lt;/p&gt;</summary></entry><entry><title type="html">jank development update - Lots of new changes</title><link href="https://jank-lang.org/blog/2022-12-08-progress-update" rel="alternate" title="jank development update - Lots of new changes" type="text/html" /><published>2022-12-08T00:00:00Z</published><updated>2022-12-08T00:00:00Z</updated><id>https://jank-lang.org/blog/2022-12-08-progress-update</id><author><name>Jeaye Wilkerson</name></author><summary type="html">&lt;p&gt;I was previously giving updates only in the &lt;a href=&quot;https://clojurians.slack.com/archives/C03SRH97FDK&quot;&gt;#jank&lt;/a&gt; Slack channel, but some of these are getting large enough to warrant more prose. Thus, happily, I can announce that jank has a new blog and I have a &lt;i&gt;lot&lt;/i&gt; of new progress to report! Let&amp;apos;s get into the details.&lt;/p&gt;</summary></entry></feed>

0 comments on commit f1a33bf

Please sign in to comment.