<?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: Juan Hurtado</title>
    <description>The latest articles on DEV Community by Juan Hurtado (@juan_hurtado).</description>
    <link>https://dev.to/juan_hurtado</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%2F4001091%2Fed9bf271-2f52-4ae2-9576-23afec8a2114.jpg</url>
      <title>DEV Community: Juan Hurtado</title>
      <link>https://dev.to/juan_hurtado</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/juan_hurtado"/>
    <language>en</language>
    <item>
      <title>How We Made Ktor JSON Parsing 66% Faster with 50% Less Memory on KMP</title>
      <dc:creator>Juan Hurtado</dc:creator>
      <pubDate>Wed, 24 Jun 2026 20:43:03 +0000</pubDate>
      <link>https://dev.to/juan_hurtado/how-we-made-ktor-json-parsing-66-faster-with-50-less-memory-on-kmp-2pca</link>
      <guid>https://dev.to/juan_hurtado/how-we-made-ktor-json-parsing-66-faster-with-50-less-memory-on-kmp-2pca</guid>
      <description>&lt;p&gt;If you are building Kotlin Multiplatform applications, you know that JSON serialization is often one of the main bottlenecks in high-throughput backends and mobile apps—especially regarding CPU cycles and Garbage Collector (GC) pressure.&lt;/p&gt;

&lt;p&gt;I’ve been working on &lt;strong&gt;Ghost Serializer&lt;/strong&gt;—a byte-first JSON serializer designed for KMP, and the official &lt;a href="https://www.http-arena.com/#sort=rps:-1&amp;amp;q=kotlin" rel="noopener noreferrer"&gt;HTTP Arena benchmarks&lt;/a&gt; just went live showing some wild improvements when integrated with Ktor.&lt;/p&gt;




&lt;h3&gt;
  
  
  📊 The Proof (HTTP Arena Benchmarks)
&lt;/h3&gt;

&lt;p&gt;Don't take my word for it. Here is the raw comparison of &lt;strong&gt;Ktor base&lt;/strong&gt; vs. &lt;strong&gt;Ktor + Ghost&lt;/strong&gt; under load:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JSON Throughput:&lt;/strong&gt; Slashed latency to jump from &lt;strong&gt;395k to 658k rps (+66.6% speedup)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heap Memory Consumption:&lt;/strong&gt; Plunged from &lt;strong&gt;9.90 GiB to 4.80 GiB (Over 50% memory reduction)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High-Load Complex APIs (API-16):&lt;/strong&gt; Throughput rose by &lt;strong&gt;+22.2%&lt;/strong&gt; while slashing memory by &lt;strong&gt;35% (from 2.00 GiB down to 1.30 GiB)&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🤝 Zero-Risk: Full Coexistence with your current Serializer
&lt;/h3&gt;

&lt;p&gt;You don't need to rewrite your entire project. &lt;strong&gt;Ghost can coexist seamlessly with your existing setup&lt;/strong&gt; (like &lt;code&gt;kotlinx.serialization&lt;/code&gt;, &lt;code&gt;Jackson&lt;/code&gt;, or &lt;code&gt;Gson&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;If Ghost doesn't find its &lt;code&gt;@GhostSerializable&lt;/code&gt; annotation on a class, it will return &lt;code&gt;null&lt;/code&gt; and let Ktor fallback to your standard serializer. This means &lt;strong&gt;you can adopt Ghost incrementally, using it only on your highest-traffic endpoints!&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  How to set up coexistence in Ktor:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;io.ktor.serialization.kotlinx.json.*&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;io.ktor.server.application.*&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;io.ktor.server.plugins.contentnegotiation.*&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;com.ghost.serialization.ktor.ghost&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;kotlinx.serialization.json.Json&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nc"&gt;Application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;module&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;install&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ContentNegotiation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// 1. Ghost handles high-performance @GhostSerializable endpoints&lt;/span&gt;
        &lt;span class="nf"&gt;ghost&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
        &lt;span class="c1"&gt;// 2. Kotlinx.serialization (or Jackson/Gson) handles the rest as fallback&lt;/span&gt;
        &lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Json&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ignoreUnknownKeys&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&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;h4&gt;
  
  
  How to define your models:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Processed by GHOST (High Performance)&lt;/span&gt;
&lt;span class="nd"&gt;@GhostSerializable&lt;/span&gt;
&lt;span class="kd"&gt;data class&lt;/span&gt; &lt;span class="nc"&gt;HighTrafficUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Long&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Processed by Kotlinx.serialization (Standard fallback)&lt;/span&gt;
&lt;span class="nd"&gt;@Serializable&lt;/span&gt;
&lt;span class="kd"&gt;data class&lt;/span&gt; &lt;span class="nc"&gt;StandardSettings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  What makes Ghost actually different?
&lt;/h3&gt;

&lt;p&gt;Unlike standard serializers that parse raw buffers into intermediate strings/chars and perform standard string matching, Ghost operates at the byte/bit level:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Compile-time Perfect Hash Finder (No String Comparison)&lt;/strong&gt;: During compilation (via KSP2), Ghost's &lt;code&gt;PerfectHashFinder&lt;/code&gt; searches for a collision-free multiplier and shift parameter for your class's fields. At runtime, the parser packs the first 4 bytes of the incoming JSON key into a 32-bit integer &lt;code&gt;key&lt;/code&gt; and resolves the field index in &lt;code&gt;O(1)&lt;/code&gt; with a simple arithmetic instruction:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;val hash = ((key * multiplier + size) shr shift) and 1023&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It accesses a precalculated dispatch table using this hash, matching fields instantly with &lt;strong&gt;zero string allocations, zero string equality checks, and zero loops&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Single CPU Instruction Required-Fields Check&lt;/strong&gt;: Instead of tracking lists, arrays, or maps of parsed fields, Ghost maps them to a single &lt;code&gt;Long&lt;/code&gt; bitmask. Validating that all required fields are present compiles down to a single bitwise CPU register check.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Byte-First Pipelines&lt;/strong&gt;: It works directly on raw source bytes (&lt;code&gt;ByteArray&lt;/code&gt; / &lt;code&gt;Okio&lt;/code&gt; / &lt;code&gt;ByteReadChannel&lt;/code&gt;). It avoids decoding JSON structures to string representations in the hot path, only decoding final string values when strictly requested.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Thread-Local Reader/Writer Pools&lt;/strong&gt;: Keeps GC allocation pressure at absolute zero in steady-state operation by reusing pre-allocated pools.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🚀 Help us build a community!
&lt;/h3&gt;

&lt;p&gt;Ghost is open-source and ready for Kotlin Multiplatform (JVM, Android, iOS, and native targets). We are looking for collaborators, feedback, and contributors to push KMP performance to its absolute limits.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt;  &lt;a href="https://github.com/juanchurtado1991/ghost-serializer" rel="noopener noreferrer"&gt;juanchurtado1991/ghost-serializer&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Setup &amp;amp; Architecture:&lt;/strong&gt; 📖 &lt;a href="https://github.com/juanchurtado1991/ghost-serializer/blob/main/docs/wiki/installation.md" rel="noopener noreferrer"&gt;Read the Installation Guide&lt;/a&gt; | &lt;a href="https://github.com/juanchurtado1991/ghost-serializer/blob/main/docs/wiki/architecture.md" rel="noopener noreferrer"&gt;Architecture Deep Dive&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Platform Docs:&lt;/strong&gt; 📱 &lt;a href="https://github.com/juanchurtado1991/ghost-serializer/blob/main/docs/wiki/usage-android.md" rel="noopener noreferrer"&gt;Android&lt;/a&gt; | &lt;a href="https://github.com/juanchurtado1991/ghost-serializer/blob/main/docs/wiki/usage-ios.md" rel="noopener noreferrer"&gt;iOS&lt;/a&gt; | &lt;a href="https://github.com/juanchurtado1991/ghost-serializer/blob/main/docs/wiki/usage-kmp.md" rel="noopener noreferrer"&gt;KMP&lt;/a&gt; | &lt;a href="https://github.com/juanchurtado1991/ghost-serializer/blob/main/docs/wiki/usage-spring-boot.md" rel="noopener noreferrer"&gt;Spring Boot&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Contributing:&lt;/strong&gt; 🤝 &lt;a href="https://github.com/juanchurtado1991/ghost-serializer/blob/main/docs/wiki/contributing.md" rel="noopener noreferrer"&gt;Want to help? Read the Contributing Guide&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you like the project, please drop a ⭐ &lt;strong&gt;Star on GitHub&lt;/strong&gt;! It helps us gain visibility, grow the community, and keep the engine running. &lt;/p&gt;

&lt;p&gt;Let me know what you think or if you want to try it out!&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>kmp</category>
      <category>performance</category>
      <category>ktor</category>
    </item>
  </channel>
</rss>
