<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: JairusSW</title>
    <description>The latest articles on DEV Community by JairusSW (@jairussw).</description>
    <link>https://dev.to/jairussw</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F664486%2F760a7463-8a3e-41c9-ab23-284f45eb0e43.jpeg</url>
      <title>DEV Community: JairusSW</title>
      <link>https://dev.to/jairussw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jairussw"/>
    <language>en</language>
    <item>
      <title>One of the most overlooked yet most powerful optimization techniques available!</title>
      <dc:creator>JairusSW</dc:creator>
      <pubDate>Mon, 14 Sep 2026 14:14:47 +0000</pubDate>
      <link>https://dev.to/jairussw/one-of-the-most-overlooked-yet-most-powerful-optimization-techniques-available-3e1j</link>
      <guid>https://dev.to/jairussw/one-of-the-most-overlooked-yet-most-powerful-optimization-techniques-available-3e1j</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/jtenner/delayed-gratification-and-valent-blocks-498o" class="crayons-story__hidden-navigation-link"&gt;Delayed Gratification and Valent Blocks&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/jtenner" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F48933%2Fd81ed70a-188a-4585-a4ae-8034ce79a19a.png" alt="jtenner profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/jtenner" class="crayons-story__secondary fw-medium m:hidden"&gt;
              jtenner
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                jtenner
                
                
              
              &lt;div id="story-author-preview-content-4650535" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/jtenner" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F48933%2Fd81ed70a-188a-4585-a4ae-8034ce79a19a.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;jtenner&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/jtenner/delayed-gratification-and-valent-blocks-498o" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Sep 14&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/jtenner/delayed-gratification-and-valent-blocks-498o" id="article-link-4650535"&gt;
          Delayed Gratification and Valent Blocks
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/performance"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;performance&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/computerscience"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;computerscience&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/opensource"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;opensource&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/jtenner/delayed-gratification-and-valent-blocks-498o" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;1&lt;span class="hidden s:inline"&gt;&amp;nbsp;reaction&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/jtenner/delayed-gratification-and-valent-blocks-498o#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              1&lt;span class="hidden s:inline"&gt;&amp;nbsp;comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>A singlepass compiler that's 70% faster than wazero, compiles 5x faster, and uses 11x less memory? hell yeah.</title>
      <dc:creator>JairusSW</dc:creator>
      <pubDate>Fri, 11 Sep 2026 03:18:18 +0000</pubDate>
      <link>https://dev.to/jairussw/a-singlepass-compiler-thats-70-faster-than-wazero-compiles-5x-faster-and-uses-11x-less-memory-5c55</link>
      <guid>https://dev.to/jairussw/a-singlepass-compiler-thats-70-faster-than-wazero-compiles-5x-faster-and-uses-11x-less-memory-5c55</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b" class="crayons-story__hidden-navigation-link"&gt;A new WebAssembly runtime enters the arena... Is it worthy?&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/jairussw" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F664486%2F760a7463-8a3e-41c9-ab23-284f45eb0e43.jpeg" alt="jairussw profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/jairussw" class="crayons-story__secondary fw-medium m:hidden"&gt;
              JairusSW
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                JairusSW
                
                
              
              &lt;div id="story-author-preview-content-4627219" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/jairussw" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F664486%2F760a7463-8a3e-41c9-ab23-284f45eb0e43.jpeg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;JairusSW&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Sep 11&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b" id="article-link-4627219"&gt;
          A new WebAssembly runtime enters the arena... Is it worthy?
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webassembly"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webassembly&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/assembly"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;assembly&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/go"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;go&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/security"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;security&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              5&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>A singlepass compiler that's 70% faster than wazero, compiles 5x faster, and uses 11x less memory? hell yeah.</title>
      <dc:creator>JairusSW</dc:creator>
      <pubDate>Fri, 11 Sep 2026 03:18:15 +0000</pubDate>
      <link>https://dev.to/jairussw/a-singlepass-compiler-thats-70-faster-than-wazero-compiles-5x-faster-and-uses-11x-less-memory-5eco</link>
      <guid>https://dev.to/jairussw/a-singlepass-compiler-thats-70-faster-than-wazero-compiles-5x-faster-and-uses-11x-less-memory-5eco</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b" class="crayons-story__hidden-navigation-link"&gt;A new WebAssembly runtime enters the arena... Is it worthy?&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/jairussw" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F664486%2F760a7463-8a3e-41c9-ab23-284f45eb0e43.jpeg" alt="jairussw profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/jairussw" class="crayons-story__secondary fw-medium m:hidden"&gt;
              JairusSW
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                JairusSW
                
                
              
              &lt;div id="story-author-preview-content-4627219" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/jairussw" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F664486%2F760a7463-8a3e-41c9-ab23-284f45eb0e43.jpeg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;JairusSW&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Sep 11&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b" id="article-link-4627219"&gt;
          A new WebAssembly runtime enters the arena... Is it worthy?
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webassembly"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webassembly&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/assembly"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;assembly&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/go"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;go&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/security"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;security&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              5&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>A new WebAssembly runtime enters the arena... Is it worthy?</title>
      <dc:creator>JairusSW</dc:creator>
      <pubDate>Fri, 11 Sep 2026 01:53:20 +0000</pubDate>
      <link>https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b</link>
      <guid>https://dev.to/jairussw/a-new-webassembly-runtime-enters-the-arena-is-it-worthy-3n8b</guid>
      <description>&lt;p&gt;A few minutes ago, I released my brand-new WebAssembly runtime, &lt;a href="https://wago.sh/" rel="noopener noreferrer"&gt;&lt;strong&gt;Wago&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There's one massive problem though.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://wasmtime.dev/" rel="noopener noreferrer"&gt;Wasmtime&lt;/a&gt; is mature, fast, and backed by the &lt;a href="https://bytecodealliance.org/" rel="noopener noreferrer"&gt;Bytecode Alliance&lt;/a&gt;. Wasmer has been around for years, V8 speaks wasm fluently, and if you're writing Go, &lt;a href="https://wazero.io/" rel="noopener noreferrer"&gt;wazero&lt;/a&gt; is already the de-facto answer.&lt;/p&gt;

&lt;p&gt;So why would I be &lt;em&gt;stupid&lt;/em&gt; enough to make a new wasm runtime?&lt;/p&gt;

&lt;p&gt;Seems like all the bases are already covered, right?&lt;/p&gt;

&lt;p&gt;...right..????&lt;/p&gt;

&lt;p&gt;Well, &lt;em&gt;kind of.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The existing runtimes are &lt;strong&gt;really&lt;/strong&gt; good, don't get me wrong. I don't think Wago exists because Wasmtime or wazero are bad. In fact, I've spent &lt;em&gt;way&lt;/em&gt; too many hours of my life staring at their codebases while building this thing.&lt;/p&gt;

&lt;p&gt;But there were a few things that still bugged me.&lt;/p&gt;

&lt;p&gt;Let me give you some backstory.&lt;/p&gt;

&lt;p&gt;The past two companies I've worked at, &lt;a href="https://hypermode.com/" rel="noopener noreferrer"&gt;Hypermode&lt;/a&gt; and &lt;a href="https://impart.security/" rel="noopener noreferrer"&gt;Impart Security&lt;/a&gt;, both use the venerable &lt;a href="https://wazero.io/" rel="noopener noreferrer"&gt;wazero&lt;/a&gt; to run isolated, secure wasm applications.&lt;/p&gt;

&lt;p&gt;And it's great!&lt;/p&gt;

&lt;p&gt;We don't need to boot thousands of Docker containers, spin up micro-VMs, or do anything crazy like that. We can use a few kilobytes of RAM to run some wasm here and a megabyte there.&lt;/p&gt;

&lt;p&gt;Wazero though...&lt;/p&gt;

&lt;h1&gt;
  
  
  wazero is slow as &lt;em&gt;hell&lt;/em&gt;.
&lt;/h1&gt;

&lt;p&gt;When I compare it to Wasmtime, it runs &lt;em&gt;much&lt;/em&gt; slower.&lt;/p&gt;

&lt;p&gt;This isn't &lt;em&gt;really&lt;/em&gt; wazero's fault though.&lt;/p&gt;

&lt;p&gt;Wasmtime gets to use &lt;a href="https://cranelift.dev/" rel="noopener noreferrer"&gt;Cranelift&lt;/a&gt;, a proper optimizing compiler that outputs excellent machine code. Wazero is meant to be simple and "just work." It doesn't aggressively chase peak performance; it chooses to ride the middle ground.&lt;/p&gt;

&lt;p&gt;Maybe I'm crazy, but I deem that &lt;em&gt;laziness&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;A quote stuck with me, and I forget who said it. It went something like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Fast hardware should bring excellence, not reason to waste it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I'll answer you myself.&lt;/p&gt;

&lt;p&gt;I &lt;em&gt;am&lt;/em&gt; crazy. I'm &lt;em&gt;GREEDY&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I want unreasonably excellent performance while using tiny amounts of RAM. I want something that steps so lightly you barely notice it. The only thing you notice is the results--a runtime that used &lt;strong&gt;kilobytes of RAM to compile&lt;/strong&gt;, generated &lt;strong&gt;less machine code than wazero&lt;/strong&gt;, runs &lt;strong&gt;substantially faster&lt;/strong&gt;, and somehow remains a &lt;strong&gt;single-pass compiler&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So, I started experimenting.&lt;/p&gt;

&lt;p&gt;At work, we can deal with poor performance by scaling, but that has a limit. More CPU costs money. More memory costs money. Eventually, &lt;em&gt;"just add another machine"&lt;/em&gt; stops being a satisfying answer.&lt;/p&gt;

&lt;p&gt;I thought,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hey, if i can reduce memory usage by 10x and improve performance by 50%, &lt;em&gt;surely&lt;/em&gt; I can cut our costs in half, right?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Compilation was especially painful for us. On some of our larger workloads, wazero could peak at &lt;strong&gt;hundreds of megabytes of memory&lt;/strong&gt; just to compile a module.&lt;/p&gt;

&lt;p&gt;That was unacceptable.&lt;/p&gt;

&lt;p&gt;So I set myself some slightly unreasonable goals.&lt;/p&gt;

&lt;p&gt;I wanted a compiler that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;used &lt;strong&gt;kilobytes&lt;/strong&gt; of memory to compile&lt;/li&gt;
&lt;li&gt;generated &lt;strong&gt;less machine code&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;compiled &lt;strong&gt;several times faster&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;produced code &lt;strong&gt;substantially faster than wazero&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;and was still &lt;strong&gt;single-pass&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Oh, and I wanted it to eventually run on &lt;strong&gt;embedded systems&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Totally reasonable, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  Okay, okay, ideas are nice and all... but did you actually accomplish anything?
&lt;/h2&gt;

&lt;p&gt;My experiments eventually became &lt;strong&gt;Railshot&lt;/strong&gt;, Wago's compiler.&lt;/p&gt;

&lt;p&gt;Railshot doesn't build some enormous IR, optimize it tens of different ways, and then &lt;em&gt;finally&lt;/em&gt; spit out pristine machine code.&lt;/p&gt;

&lt;p&gt;It mostly just goes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.wasm → analyze → compile → machine code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That sounds horribly naïve. And, traditionally, it is.&lt;/p&gt;

&lt;p&gt;Single-pass compilers are incredibly fast to compile with, but they generally produce worse code. Optimizing compilers get to look at the entire function, analyze it, shuffle things around, run optimization passes, and make globally better decisions.&lt;/p&gt;

&lt;p&gt;Railshot doesn't get that luxury.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;But scarcity brings excellence, because to overcome your limitations, you &lt;em&gt;must&lt;/em&gt; become more than you ever imagined.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The wonderful thing about WebAssembly is that binaries often arrive &lt;strong&gt;already optimized&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If your &lt;code&gt;.wasm&lt;/code&gt; came out of LLVM, Rust, TinyGo, or another optimizing compiler, a whole bunch of work has already happened before Wago ever sees it.&lt;/p&gt;

&lt;p&gt;I don't necessarily need Railshot to rediscover everything the frontend compiler already figured out.&lt;/p&gt;

&lt;p&gt;WebAssembly is also beautifully structured! Blocks, loops, branches, types, and the operand stack give the compiler a surprising amount of information basically &lt;em&gt;for free&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;So, instead of building a giant IR, I tried to exploit that structure directly, which led me to something called &lt;strong&gt;Valent Blocks&lt;/strong&gt; (go read the &lt;a href="https://ieeexplore.ieee.org/document/9231154" rel="noopener noreferrer"&gt;research paper&lt;/a&gt; about it if you want to go down that rabbit hole).&lt;/p&gt;

&lt;p&gt;The basic idea is to maintain small, temporary views of the program that give Railshot just enough information to make smarter decisions &lt;strong&gt;while it is compiling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;register pinning&lt;/li&gt;
&lt;li&gt;bounds-check elimination&lt;/li&gt;
&lt;li&gt;instruction combining&lt;/li&gt;
&lt;li&gt;constant folding&lt;/li&gt;
&lt;li&gt;branch simplification&lt;/li&gt;
&lt;li&gt;avoiding unnecessary loads and stores&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;...all without turning Railshot into a traditional (fat) optimizing compiler.&lt;/p&gt;

&lt;p&gt;In other words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Cheat as much as possible while remaining single-pass.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I suppose there's some tipping point where cheating becomes more &lt;em&gt;smart&lt;/em&gt; than it is lazy.&lt;/p&gt;

&lt;p&gt;And somehow...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;it worked.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's see those numbers though...
&lt;/h2&gt;

&lt;p&gt;Here's the obligatory disclaimer:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;I wrote Wago. I also ran these benchmarks.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Please go run them yourself.&lt;/p&gt;

&lt;p&gt;Seriously. Please.&lt;/p&gt;

&lt;p&gt;That said... Here's a few corpora&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution Latency&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyw31wpblsoh4q1opu5v3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyw31wpblsoh4q1opu5v3.png" alt=" " width="800" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compile Latency&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq2ks3etjt0cr1hw0rmff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq2ks3etjt0cr1hw0rmff.png" alt=" " width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compile Heap&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F74knbb44urs8cyq6iotm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F74knbb44urs8cyq6iotm.png" alt=" " width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The full benchmark tables are &lt;a href="https://wago.sh/#performance" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Across my current corpus, Wago is roughly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;5.7×&lt;/strong&gt; faster to compile&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;11×&lt;/strong&gt; less memory-hungry during compilation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;70%&lt;/strong&gt; faster at execution&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;52%&lt;/strong&gt; smaller in generated machine code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not bad for a compiler that's &lt;em&gt;supposed&lt;/em&gt; to be generating bad code.&lt;/p&gt;

&lt;p&gt;The compilation memory is probably the result I'm happiest with.&lt;/p&gt;

&lt;p&gt;I wanted running wasm to be cheap enough that you just...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;don't need to worry about it.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Ooh, but can it run real stuff?
&lt;/h2&gt;

&lt;p&gt;A fast compiler isn't much use if it can only run Fibonacci and some compression algorithms.&lt;/p&gt;

&lt;p&gt;So Wago has grown into quite a bit more than Railshot.&lt;/p&gt;

&lt;p&gt;Today, Wago has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;support for &lt;strong&gt;modern WebAssembly&lt;/strong&gt; (3.0+!)&lt;/li&gt;
&lt;li&gt;extremely cheap instance creation&lt;/li&gt;
&lt;li&gt;standalone native executables&lt;/li&gt;
&lt;li&gt;a cool plugin system&lt;/li&gt;
&lt;li&gt;AMD64 and ARM64 native backends (risc-v in the works!)&lt;/li&gt;
&lt;li&gt;macos, linux, and windows support&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And here's where things start getting a little weird.&lt;/p&gt;

&lt;p&gt;Wago's plugin system can extend the runtime itself.&lt;/p&gt;

&lt;p&gt;Not just add &lt;em&gt;another&lt;/em&gt; host function.&lt;/p&gt;

&lt;p&gt;I mean &lt;strong&gt;custom WebAssembly instructions and types&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I've even implemented wider SIMD support including &lt;strong&gt;512-bit vectors backed by AVX-512 where available&lt;/strong&gt; as a &lt;a href="https://plugins.wago.sh/JairusSW/wide" rel="noopener noreferrer"&gt;&lt;em&gt;plugin&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsnu5jtmkp61u0spq4j7x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsnu5jtmkp61u0spq4j7x.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's the kind of insanity I wanted Wago's architecture to allow. A runtime that belongs to you. A runtime that doesn't worry you. A runtime that gives you all the freedom you could imagine.&lt;/p&gt;

&lt;p&gt;I mean, wasmer is like some cloud-container-pass thing right now. I don't want that.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;rather than paying wasmer, you can always &lt;a href="https://github.com/sponsors/JairusSW" rel="noopener noreferrer"&gt;sponsor&lt;/a&gt; me :) :P :O :D &amp;lt;3&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Want WASI?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wago add wago-org/wasi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't want WASI?&lt;/p&gt;

&lt;p&gt;No biggie. You're in control.&lt;br&gt;
You don't pay for it.&lt;/p&gt;

&lt;p&gt;I want users to have &lt;em&gt;full&lt;/em&gt; control over &lt;em&gt;&lt;strong&gt;their&lt;/strong&gt;&lt;/em&gt; WebAssembly runtime.&lt;/p&gt;

&lt;p&gt;That's basically the philosophy behind this whole project:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Do as little work as possible, but do that work extremely well.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  So... is it worthy?
&lt;/h2&gt;

&lt;p&gt;Honestly?&lt;/p&gt;

&lt;p&gt;I don't know yet.&lt;/p&gt;

&lt;p&gt;Wago is brand new.&lt;/p&gt;

&lt;p&gt;Wasmtime and wazero have years of production use and thousands of people finding increasingly creative ways to break them.&lt;/p&gt;

&lt;p&gt;No benchmark chart can fake that kind of maturity.&lt;/p&gt;

&lt;p&gt;There are bugs in Wago.&lt;/p&gt;

&lt;p&gt;There will be breaking changes.&lt;/p&gt;

&lt;p&gt;Somebody is probably going to read this post, download it, and immediately find a &lt;code&gt;.wasm&lt;/code&gt; file that makes Railshot do something incredibly stupid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I genuinely hope you do.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I've spent the past few months testing Wago against workloads that &lt;em&gt;I&lt;/em&gt; chose.&lt;/p&gt;

&lt;p&gt;Now I want yours.&lt;/p&gt;

&lt;p&gt;Run your weirdest wasm.&lt;/p&gt;

&lt;p&gt;Benchmark it.&lt;/p&gt;

&lt;p&gt;Throw Rust at it.&lt;/p&gt;

&lt;p&gt;Throw Go at it.&lt;/p&gt;

&lt;p&gt;Throw C and C++ at it.&lt;/p&gt;

&lt;p&gt;Try it on a microcontroller.&lt;/p&gt;

&lt;p&gt;Find somewhere wazero demolishes it.&lt;/p&gt;

&lt;p&gt;Make it panic.&lt;/p&gt;

&lt;p&gt;Make it segfault.&lt;/p&gt;

&lt;p&gt;Make it generate absolutely atrocious machine code.&lt;/p&gt;

&lt;p&gt;Then &lt;a href="https://github.com/wago-org/wago/issues" rel="noopener noreferrer"&gt;&lt;strong&gt;open an issue&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's see how far we can take this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Together.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Please give it a try :)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go run github.com/wago-org/wago/cli/wago-installer@main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;P.S. please join our &lt;a href="https://wago.sh/discord" rel="noopener noreferrer"&gt;Discord&lt;/a&gt; to discuss stuff, mull over features, and test new releases!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webassembly</category>
      <category>assembly</category>
      <category>go</category>
      <category>security</category>
    </item>
    <item>
      <title>Quickly detecting JSON Escapes with SWAR</title>
      <dc:creator>JairusSW</dc:creator>
      <pubDate>Wed, 01 Apr 2026 05:27:14 +0000</pubDate>
      <link>https://dev.to/jairussw/quickly-detecting-json-escapes-with-swar-52p5</link>
      <guid>https://dev.to/jairussw/quickly-detecting-json-escapes-with-swar-52p5</guid>
      <description>&lt;p&gt;Most JSON string data is boring.&lt;/p&gt;

&lt;p&gt;It is just ASCII text that does not contain &lt;code&gt;"&lt;/code&gt; or &lt;code&gt;\&lt;/code&gt;, does not dip below &lt;code&gt;0x20&lt;/code&gt;, and does not force any special-case escaping at all.&lt;/p&gt;

&lt;p&gt;The annoying part is that a serializer still has to prove that.&lt;/p&gt;

&lt;p&gt;The naive loop is obvious:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charCodeAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;92&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// escape&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is correct, but it is also one branch per code unit in the hottest part of the serializer.&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;json-as&lt;/code&gt;, I wanted the fast path to ask a cheaper question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Does this whole chunk contain anything interesting at all?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is where &lt;a href="https://en.wikipedia.org/wiki/SWAR" rel="noopener noreferrer"&gt;SWAR&lt;/a&gt; fits nicely.&lt;/p&gt;

&lt;p&gt;For this post, the companion code is here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/blog/tree/main/code/quickly-detecting-escapes-with-swar/00-detector-functions" rel="noopener noreferrer"&gt;&lt;code&gt;00-detector-functions&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/blog/tree/main/code/quickly-detecting-escapes-with-swar/01-c-and-wasm-benchmark" rel="noopener noreferrer"&gt;&lt;code&gt;01-c-and-wasm-benchmark&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/blog/tree/main/code/quickly-detecting-escapes-with-swar/02-assemblyscript-inspection" rel="noopener noreferrer"&gt;&lt;code&gt;02-assemblyscript-inspection&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What needs detecting?
&lt;/h2&gt;

&lt;p&gt;When serializing a JSON string, these are the lanes that matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;"&lt;/code&gt; because it must become &lt;code&gt;\"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;\&lt;/code&gt; because it must become &lt;code&gt;\\&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;control characters &lt;code&gt;&amp;lt; 0x20&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;non-ASCII UTF-16 code units, because they cannot stay on the pure ASCII copy path&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If I can classify four UTF-16 lanes at once inside one &lt;code&gt;u64&lt;/code&gt;, then the common case becomes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;load 8 bytes&lt;/li&gt;
&lt;li&gt;compute a mask&lt;/li&gt;
&lt;li&gt;copy directly if the mask is zero&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is the whole job of this helper written in the &lt;a href="https://assemblyscript.org/" rel="noopener noreferrer"&gt;AssemblyScript Language&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;inline&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;detect_escapable_u64_swar_safe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;u64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x00ff&lt;/span&gt;&lt;span class="nx"&gt;_00ff_00ff_00ff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ascii_mask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0020&lt;/span&gt;&lt;span class="nx"&gt;_0020_0020_0020&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x0022&lt;/span&gt;&lt;span class="nx"&gt;_0022_0022_0022&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0001&lt;/span&gt;&lt;span class="nx"&gt;_0001_0001_0001&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x005c&lt;/span&gt;&lt;span class="nx"&gt;_005c_005c_005c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0001&lt;/span&gt;&lt;span class="nx"&gt;_0001_0001_0001&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x0080&lt;/span&gt;&lt;span class="nx"&gt;_0080_0080_0080&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hi_mask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0100&lt;/span&gt;&lt;span class="nx"&gt;_0100_0100_0100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x8000&lt;/span&gt;&lt;span class="nx"&gt;_8000_8000_8000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x8000&lt;/span&gt;&lt;span class="nx"&gt;_8000_8000_8000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ascii_mask&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="nx"&gt;hi_mask&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;hi_mask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks cryptic, but it is just two independent predicates packed into one result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why UTF-16 makes this convenient
&lt;/h2&gt;

&lt;p&gt;AssemblyScript strings are UTF-16, and that matters a lot here.&lt;/p&gt;

&lt;p&gt;For plain ASCII text:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the low byte of each 16-bit lane contains the character&lt;/li&gt;
&lt;li&gt;the high byte is zero&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That gives a very convenient layout. I can inspect the low bytes for JSON escape cases, and separately inspect the high bytes to notice when the block is no longer plain ASCII.&lt;/p&gt;

&lt;p&gt;So this is not a universal string trick. It is a particularly good fit for UTF-16 data.&lt;/p&gt;

&lt;h2&gt;
  
  
  The low-byte test
&lt;/h2&gt;

&lt;p&gt;First, isolate the low byte of each UTF-16 lane:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x00ff&lt;/span&gt;&lt;span class="nx"&gt;_00ff_00ff_00ff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I only care about three low-byte predicates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt; 0x20&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;== 0x22&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;== 0x5c&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The detector builds those without branches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ascii_mask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0020&lt;/span&gt;&lt;span class="nx"&gt;_0020_0020_0020&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x0022&lt;/span&gt;&lt;span class="nx"&gt;_0022_0022_0022&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0001&lt;/span&gt;&lt;span class="nx"&gt;_0001_0001_0001&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x005c&lt;/span&gt;&lt;span class="nx"&gt;_005c_005c_005c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0001&lt;/span&gt;&lt;span class="nx"&gt;_0001_0001_0001&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x0080&lt;/span&gt;&lt;span class="nx"&gt;_0080_0080_0080&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is standard SWAR arithmetic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;subtraction to manufacture per-lane underflow or equality signals&lt;/li&gt;
&lt;li&gt;masking to collapse those signals into lane-local high bits&lt;/li&gt;
&lt;li&gt;no per-character branch in the hot path&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If one of the four low bytes looks special, its lane gets marked in &lt;code&gt;ascii_mask&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The high-byte test
&lt;/h2&gt;

&lt;p&gt;That still leaves non-ASCII code units.&lt;/p&gt;

&lt;p&gt;The ASCII trick only works when every high byte is zero, so the detector also asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Is any UTF-16 high byte non-zero?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is what this part does:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hi_mask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0100&lt;/span&gt;&lt;span class="nx"&gt;_0100_0100_0100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x8000&lt;/span&gt;&lt;span class="nx"&gt;_8000_8000_8000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x8000&lt;/span&gt;&lt;span class="nx"&gt;_8000_8000_8000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is a mask over the high bytes of the four lanes. If a lane is not plain ASCII, that lane is marked.&lt;/p&gt;

&lt;p&gt;Then the final merge is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ascii_mask&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="nx"&gt;hi_mask&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;hi_mask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;keep the ASCII escape hits for truly ASCII lanes&lt;/li&gt;
&lt;li&gt;also mark any lane whose high byte is non-zero&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The serializer now has exactly the answer it needs:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Which lanes force me off the pure ASCII copy path?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The unsafe variant
&lt;/h2&gt;

&lt;p&gt;There is also a cheaper detector:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;inline&lt;/span&gt; &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;detect_escapable_u64_swar_unsafe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;u64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x00ff&lt;/span&gt;&lt;span class="nx"&gt;_00ff_00ff_00ff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ascii_mask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0020&lt;/span&gt;&lt;span class="nx"&gt;_0020_0020_0020&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x0022&lt;/span&gt;&lt;span class="nx"&gt;_0022_0022_0022&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0001&lt;/span&gt;&lt;span class="nx"&gt;_0001_0001_0001&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x005c&lt;/span&gt;&lt;span class="nx"&gt;_005c_005c_005c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x0001&lt;/span&gt;&lt;span class="nx"&gt;_0001_0001_0001&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x0080&lt;/span&gt;&lt;span class="nx"&gt;_0080_0080_0080&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="nx"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;ascii_mask&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0xff00&lt;/span&gt;&lt;span class="nx"&gt;_ff00_ff00_ff00&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This one does not prove that a non-ASCII lane is really dangerous. It just marks any lane with a non-zero high byte and lets the later slow path sort it out.&lt;/p&gt;

&lt;p&gt;That means more false positives, but a smaller and faster detector.&lt;/p&gt;

&lt;p&gt;So the tradeoff is simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;safe&lt;/code&gt;: do more proof up front&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;unsafe&lt;/code&gt;: bail out faster and prove less on the hot path&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your strings are mostly ASCII, that is often a good deal.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the serializer gets from this
&lt;/h2&gt;

&lt;p&gt;Once you have the mask, the fast path becomes tiny:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;load&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;u64&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;srcStart&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;detect_escapable_u64_swar_unsafe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mask&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;laneIdx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ctz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mask&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// clear low and high bytes&lt;/span&gt;
    &lt;span class="nx"&gt;mask&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;=&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0xffff&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;laneIdx&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="c1"&gt;// even (0 2 4 6) -&amp;gt; confirmed ascii escape&lt;/span&gt;
    &lt;span class="c1"&gt;// odd (1 3 5 7) -&amp;gt; possibly a unicode code unit or surrogate&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;laneIdx&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// handle non-surrogates (fast path)&lt;/span&gt;
      &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// and handle surrogates here (unlikely to be hit)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the payoff.&lt;/p&gt;

&lt;p&gt;For ordinary ASCII blocks with no escapes, the serializer just copies 8 bytes and moves on.&lt;/p&gt;

&lt;p&gt;Only when the mask is non-zero does it need to identify the exact lane and expand the escape sequence.&lt;/p&gt;

&lt;p&gt;That shifts the cost model in the right direction. Instead of repeatedly asking “does this character need escaping?”, the hot path asks “is there anything interesting in this whole block?”&lt;/p&gt;

&lt;h2&gt;
  
  
  Benchmarking safe vs unsafe
&lt;/h2&gt;

&lt;p&gt;I reran the detector-only benchmark with matching harness shapes in both implementations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AssemblyScript compiled to Wasm and run with &lt;code&gt;wasmer --llvm --enable-pass-params-opt&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;native C compiled with aggressive host-tuned flags and LTO&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both versions use the same payload size, warmup policy, operation count, and logging structure. The benchmark code is here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/blog/blob/main/code/quickly-detecting-escapes-with-swar/01-c-and-wasm-benchmark/wasm-bench.ts" rel="noopener noreferrer"&gt;&lt;code&gt;wasm-bench.ts&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/blog/blob/main/code/quickly-detecting-escapes-with-swar/01-c-and-wasm-benchmark/bench.c" rel="noopener noreferrer"&gt;&lt;code&gt;bench.c&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/blog/blob/main/code/quickly-detecting-escapes-with-swar/01-c-and-wasm-benchmark/bench-lib.h" rel="noopener noreferrer"&gt;&lt;code&gt;bench-lib.h&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The two payload shapes are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;plain ASCII text with no escapes&lt;/li&gt;
&lt;li&gt;escape-heavy text with quotes, backslashes, and control characters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are the current numbers from that harness:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Case&lt;/th&gt;
&lt;th&gt;Wasm / &lt;code&gt;wasmer --llvm --enable-pass-params-opt&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;Native C&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;safe / plain&lt;/td&gt;
&lt;td&gt;5030 MB/s&lt;/td&gt;
&lt;td&gt;6824 MB/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;unsafe / plain&lt;/td&gt;
&lt;td&gt;6355 MB/s&lt;/td&gt;
&lt;td&gt;8562 MB/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;safe / escaped&lt;/td&gt;
&lt;td&gt;4908 MB/s&lt;/td&gt;
&lt;td&gt;6295 MB/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;unsafe / escaped&lt;/td&gt;
&lt;td&gt;7093 MB/s&lt;/td&gt;
&lt;td&gt;8331 MB/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That is exactly what I wanted to know. The unsafe detector is not just theoretically smaller. It buys measurable throughput in the actual runtime I care about. When integrating it into an actual JSON serializer, it's marginally faster too.&lt;/p&gt;

&lt;p&gt;If you want to rerun it, the example folder is here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/blog/tree/main/code/quickly-detecting-escapes-with-swar/01-c-and-wasm-benchmark" rel="noopener noreferrer"&gt;&lt;code&gt;01-c-and-wasm-benchmark&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the commands are just:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make &lt;span class="nb"&gt;install
&lt;/span&gt;make build
make run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Looking at the generated code
&lt;/h2&gt;

&lt;p&gt;The throughput numbers tell you the tradeoff is real, but the code shape explains why.&lt;/p&gt;

&lt;p&gt;The unsafe detector compiles to a smaller body because it skips the extra high-byte proof/merge logic from the safe version. That is easiest to see in the inspection example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/blog/tree/main/code/quickly-detecting-escapes-with-swar/02-assemblyscript-inspection" rel="noopener noreferrer"&gt;&lt;code&gt;02-assemblyscript-inspection&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is nothing magical there. The unsafe version is just doing less work.&lt;/p&gt;

&lt;p&gt;If you want to see the real implementation in context, these are the relevant &lt;code&gt;json-as&lt;/code&gt; sources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/json-as/blob/main/assembly/serialize/swar/string.ts" rel="noopener noreferrer"&gt;json-as &lt;code&gt;assembly/serialize/swar/string.ts&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JairusSW/json-as/blob/main/assembly/util/swar.ts" rel="noopener noreferrer"&gt;json-as &lt;code&gt;assembly/util/swar.ts&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>performance</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Quickly parsing Unicode Escapes with SWAR</title>
      <dc:creator>JairusSW</dc:creator>
      <pubDate>Mon, 05 Jan 2026 22:16:14 +0000</pubDate>
      <link>https://dev.to/jairussw/quickly-parsing-unicode-escapes-with-swar-3n7p</link>
      <guid>https://dev.to/jairussw/quickly-parsing-unicode-escapes-with-swar-3n7p</guid>
      <description>&lt;p&gt;Last night I went down a rabbit hole optimizing Unicode escape decoding in a JSON parser using &lt;a href="https://en.wikipedia.org/wiki/SWAR" rel="noopener noreferrer"&gt;SWAR&lt;/a&gt; (SIMD Within A Register) techniques.&lt;/p&gt;

&lt;p&gt;Even though unicode escapes don't occur often on average, making it a cold path, I still wanted to see how far a purely arithmetic approach could be pushed. I considered using a &lt;a href="https://en.wikipedia.org/wiki/Lookup_table" rel="noopener noreferrer"&gt;LUT&lt;/a&gt; (LookUp Table), but it took more cpu cycles than ideal. Eventually though I stumbled upon this stunningly beautiful little function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0xF&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It may seem insignificant, but this function maps ASCII hex characters (&lt;code&gt;0-9&lt;/code&gt;, &lt;code&gt;A-F&lt;/code&gt;, &lt;code&gt;a-f&lt;/code&gt;) to their numeric values without branches or tables.&lt;/p&gt;

&lt;p&gt;My use case though, was to parse unicode escape sequences in JSON quickly and efficiently, meaning that I'd have to run this function for each nibble in \uXXXX, which makes it a computational drain.&lt;/p&gt;

&lt;p&gt;Instead of converting each character one-by-one with the previous function, I can utilize SIMD Within A Register. SWAR lets you run the same logic on all four nibbles in parallel inside a single 64-bit register, meaning that I can easily parallelize this to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Convert a single \uXXXX -&amp;gt; u16. Assume UTF/WTF-16&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;inline&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;hex4_to_u16_swar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;u16&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// (c &amp;amp; 0xF) + 9 * (c &amp;gt;&amp;gt; 6)&lt;/span&gt;
  &lt;span class="c1"&gt;// Perform the above function for all nibbles in parallel&lt;/span&gt;
  &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x0F000F000F000F&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x03000300030003&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Pack each nibble into a u16&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;u16&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, I can parse JSON strings at over 7GB/s. Hooray! 🎉&lt;/p&gt;

&lt;p&gt;Low-level tricks aren't always necessary, given the excess of computing power we live in today, but when they do apply, they sure are hard to beat.&lt;/p&gt;

&lt;p&gt;You can view the source here: &lt;a href="https://github.com/JairusSW/json-as/blob/main/assembly/util/swar.ts#L3" rel="noopener noreferrer"&gt;https://github.com/JairusSW/json-as&lt;/a&gt;&lt;/p&gt;

</description>
      <category>performance</category>
      <category>programming</category>
      <category>webassembly</category>
    </item>
    <item>
      <title>So, you can benchmark in AssemblyScript...</title>
      <dc:creator>JairusSW</dc:creator>
      <pubDate>Sat, 14 May 2022 22:18:36 +0000</pubDate>
      <link>https://dev.to/jairussw/so-you-can-benchmark-in-assemblyscript-3d2</link>
      <guid>https://dev.to/jairussw/so-you-can-benchmark-in-assemblyscript-3d2</guid>
      <description>&lt;p&gt;Introducing... &lt;a href="https://github.com/romdotdog/as-tral" rel="noopener noreferrer"&gt;Astral&lt;/a&gt;--A minimalistic benchmarking library for AssemblyScript. Based off of criterion.rs.&lt;br&gt;
With this new benchmarking tool, we are able to easily visualize and optimize performance in our code precisely. Usually, we would have to use a while loop and &lt;code&gt;Date.now&lt;/code&gt; or &lt;code&gt;performance.now&lt;/code&gt; bindings to measure performance. Astral adds warmup periods, logging, and a few other tools. Lets get started!&lt;br&gt;
In an existing AssemblyScript project, install as-tral.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D @as-tral/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a &lt;strong&gt;benches&lt;/strong&gt; folder in your assembly directory. Add a file named as-tral.d.ts in there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;assembly/
└── __benches__/
    └── as-tral.d.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In as-tral.d.ts, copy and paste&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;reference path="../../node_modules/@as-tral/cli/as-tral.d.ts" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stick any file with a .ts extension in &lt;strong&gt;benches&lt;/strong&gt;. You can even have multiple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;assembly/
└── __benches__/
    ├── as-tral.d.ts
    └── my-benchmark.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your benchmark will live in this file. Let's create an example benchmark.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// to ensure accurate benchmarks, we must make sure that binaryen doesn't do any sneaky&lt;/span&gt;
&lt;span class="c1"&gt;// optimizations on our input without us knowing. Thus, we must use `blackbox`.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;blackbox&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The quick brown fox jumped over the lazy dog.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// our string here must be a compile time constant.&lt;/span&gt;
&lt;span class="c1"&gt;// open an issue if you'd like to see this constraint lifted.&lt;/span&gt;
&lt;span class="nf"&gt;bench&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string split&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// this function body will be run many times.&lt;/span&gt;
    &lt;span class="c1"&gt;// we must make sure our compiler won't throw away the computation,&lt;/span&gt;
    &lt;span class="c1"&gt;// so we use `blackbox` here again.&lt;/span&gt;
    &lt;span class="nf"&gt;blackbox&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's run as-tral.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rom@i9-cabin:~/demo$ npx astral
Compiling assembly/__benches__/hello.ts

Benchmarking string split: Warming up for 3000ms
Benchmarking string split: Collecting 100 samples in estimated 5018.6ms (1.2M iterations)
Benchmarking string split: Analyzing
string split            time: [3770.9ns 3775ns 3778.9ns]
Found 4 outliers among 100 measurements (4%)
  3 (3%) low mild
  1 (1%) high mild
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty great!&lt;/p&gt;

</description>
      <category>assemblyscript</category>
      <category>webassembly</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JSON in AssemblyScript</title>
      <dc:creator>JairusSW</dc:creator>
      <pubDate>Tue, 20 Jul 2021 14:44:53 +0000</pubDate>
      <link>https://dev.to/assemblyscript/json-in-assemblyscript-28cg</link>
      <guid>https://dev.to/assemblyscript/json-in-assemblyscript-28cg</guid>
      <description>&lt;p&gt;&lt;strong&gt;Finally, AssemblyScript has a fully-functional JSON implementation.&lt;/strong&gt; &lt;em&gt;&lt;a href="https://github.com/aspkg/as-json" rel="noopener noreferrer"&gt;as-json&lt;/a&gt;&lt;/em&gt; implements full JSON compatibility that enables AssemblyScript to use JSON to communicate with APIs, store data, and more. In this article, I will introduce you to &lt;em&gt;as-json&lt;/em&gt; and help you include it into your project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;as-json&lt;/em&gt; uses the same general API as the JavaScript JSON object. We can then use it just like JS. However, we must install and prep it first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;json-as
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--transform&lt;/span&gt; json-as/transform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Installation complete. Lets use some JSON! 🔥&lt;/p&gt;

&lt;p&gt;&lt;em&gt;json-test.ts&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;json-as&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// Create the Schemas&lt;/span&gt;
&lt;span class="c1"&gt;// @ts-ignore&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;json&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;JSONSchema&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;human&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;language&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// @ts-ignore&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;json&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;country&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;awesome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Create the JSON object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSONSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jairus&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tanaka&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;human&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;country&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;US&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;awesome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;language&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;english&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;43.130850291&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;32.926401705&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Now, encode and decode&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;encoded&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Encoded: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;encoded&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decoded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;JSONSchema&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;encoded&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Decoded:`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`{`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` firstName: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` lastName: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` age: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` human: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;human&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` meta: {`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`   country: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;country&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`   awesome: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;awesome&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` },`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` language: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;language&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` location: [&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt;]`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`}`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: If you are not running in WASI, use as-console instead.&lt;/p&gt;

&lt;p&gt;So, &lt;em&gt;json-as&lt;/em&gt; serialized and deserialized JSON. Lets see if it was correct.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;json-test.ts&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;json-as&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// Create the Schemas&lt;/span&gt;
&lt;span class="c1"&gt;// @ts-ignore&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;json&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;JSONSchema&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;human&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;language&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// @ts-ignore&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;json&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;country&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;awesome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Create the JSON object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSONSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jairus&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tanaka&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;human&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;country&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;US&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;awesome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;language&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;english&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;43.130850291&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;32.926401705&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Now, encode and decode&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;encoded&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decoded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;JSONSchema&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;encoded&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// We perform an equality check&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;encoded&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yay! JSON-AS works! 😄&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Oof. JSON-AS died.😖&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yay! JSON is now working for AssemblyScript. Go ahead and mess around with it and let me know what you make.&lt;br&gt;
With the up-and-coming release of JSON-AS v0.2.0, full dynamic objects and arrays will be supported.&lt;br&gt;
NPM: &lt;a href="https://www.npmjs.com/package/json-as" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/json-as&lt;/a&gt;&lt;br&gt;
GitHub: &lt;a href="https://github.com/aspkg/as-json" rel="noopener noreferrer"&gt;https://github.com/aspkg/as-json&lt;/a&gt;&lt;br&gt;
Thanks for reading 😁&lt;/p&gt;

</description>
      <category>webassembly</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>assemblyscript</category>
    </item>
    <item>
      <title>What is AssemblyScript?</title>
      <dc:creator>JairusSW</dc:creator>
      <pubDate>Mon, 12 Jul 2021 18:34:40 +0000</pubDate>
      <link>https://dev.to/assemblyscript/what-is-assemblyscript-3gfl</link>
      <guid>https://dev.to/assemblyscript/what-is-assemblyscript-3gfl</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4uj09a30exiqxep28hd.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4uj09a30exiqxep28hd.jpeg" alt="Alt Text" width="700" height="350"&gt;&lt;/a&gt;&lt;br&gt;
  AssemblyScript — a variant of TypeScript that compiles to WebAssembly. Since it is compiled, it outperforms JavaScript in some cases. AS follows the TypeScript syntax as closely as possible and even adds more features to it. AssemblyScript allows us to write fast WebAssembly for the Web and Server without learning another language.&lt;/p&gt;

&lt;p&gt;AssemblyScript is very easy to use. All you need to do is install it via NPM.&lt;/p&gt;

&lt;p&gt;Try it out online: &lt;a href="https://stackblitz.com/edit/node-quzm4z?devtoolsheight=33&amp;amp;file=test.js" rel="noopener noreferrer"&gt;Online editor&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ npm i assemblyscript &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
~ npx asinit &lt;span class="nb"&gt;.&lt;/span&gt;
~ npm i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What did that do? First of all, it installed both the loader and the compiler. Secondly, it made a template project with an add function. Now, we just need to compile it to WebAssembly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ npm run asbuild
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, if you check out the /build folder, there are the .wasm files that were built. NodeJS and JavaScript both provide a way to run WebAssembly files and AssemblyScript provides its own loader to work with the code. To start our code, we need another file&lt;/p&gt;

&lt;p&gt;&lt;em&gt;test.js&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wasmModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// This works just like a normal module&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wasmModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;// -- 11&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, run it!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ node test.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should have outputted the number 11.&lt;/p&gt;

&lt;p&gt;JavaScript code for the add function would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The AssemblyScript code looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;i32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty similar, right? When we compile it, we can require it just like a normal JavaScript file. Keep in mind that WebAssembly is sandboxed which means it can’t access the system, make HTTP requests, or log to the console. However, AssemblyScript supports both WASI and JS bindings (calling JS from AS).&lt;/p&gt;

&lt;p&gt;If you have any questions or comments, feel free to comment or join the AssemblyScript Discord. Or, check out the website.😉&lt;/p&gt;

&lt;p&gt;P.S: There is a tutorial at &lt;a href="https://jtanaka.gitbook.io/guide/" rel="noopener noreferrer"&gt;https://jtanaka.gitbook.io/guide/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webassembly</category>
      <category>typescript</category>
      <category>assemblyscript</category>
    </item>
  </channel>
</rss>
