<?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: Gargee Bhattacharjee</title>
    <description>The latest articles on DEV Community by Gargee Bhattacharjee (@gargee_bhattacharjee_25ae).</description>
    <link>https://dev.to/gargee_bhattacharjee_25ae</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%2F4060994%2Fee565756-9344-4ebb-b905-858e0359f394.png</url>
      <title>DEV Community: Gargee Bhattacharjee</title>
      <link>https://dev.to/gargee_bhattacharjee_25ae</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gargee_bhattacharjee_25ae"/>
    <language>en</language>
    <item>
      <title>Building jugaad-mustache: Porting mustache.js to Safe, 30x Faster Rust 🦀</title>
      <dc:creator>Gargee Bhattacharjee</dc:creator>
      <pubDate>Mon, 03 Aug 2026 16:32:44 +0000</pubDate>
      <link>https://dev.to/gargee_bhattacharjee_25ae/building-jugaad-mustache-porting-mustachejs-to-safe-30x-faster-rust-49h2</link>
      <guid>https://dev.to/gargee_bhattacharjee_25ae/building-jugaad-mustache-porting-mustachejs-to-safe-30x-faster-rust-49h2</guid>
      <description>&lt;h1&gt;
  
  
  I Ported mustache.js to Safe Rust in 72 Hours — Here's What Actually Broke
&lt;/h1&gt;

&lt;p&gt;By &lt;strong&gt;Gargee Bhattacharjee&lt;/strong&gt; | &lt;strong&gt;Port Mortem 2026&lt;/strong&gt; | &lt;strong&gt;Track F&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;When competing in &lt;strong&gt;Port Mortem 2026&lt;/strong&gt; (Track F), I set out to tackle a problem almost every developer runs into: why do we need a 45 MB Node.js runtime and 47 MB of &lt;code&gt;node_modules&lt;/code&gt; just to render a basic template from a shell script?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mustache.js&lt;/code&gt; is an absolute classic in web development. But using it as a command-line tool or inside CI pipelines feels unnecessarily heavy. Cold startup takes ~150ms before your template even starts rendering. &lt;/p&gt;

&lt;p&gt;I decided to build &lt;strong&gt;&lt;code&gt;jugaad-mustache&lt;/code&gt;&lt;/strong&gt; (&lt;code&gt;mustache-rs&lt;/code&gt;) — a zero-dependency, static Rust binary that compiles to ~2MB, executes in &lt;strong&gt;5ms (30× faster)&lt;/strong&gt;, and preserves 100% behavioral equivalence with &lt;code&gt;mustache.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is the complete 4-minute video walkthrough of the finished project:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/sOZluEz885s"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  What Actually Broke (The Unexpected Edge Cases)
&lt;/h2&gt;

&lt;p&gt;Porting a dynamic JavaScript engine to a strongly-typed language like Rust sounds straightforward until you start running original spec test suites. Here are the unexpected technical hurdles I ran into:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. JavaScript's "Truthiness" vs. Rust's Type System
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;mustache.js&lt;/code&gt;, section blocks evaluate using JavaScript's implicit truthiness rules. Values like &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;0.0&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt;, and &lt;code&gt;""&lt;/code&gt; are all falsy, while empty objects &lt;code&gt;{}&lt;/code&gt; evaluate to truthy.&lt;/p&gt;

&lt;p&gt;Rust doesn't coerce numbers into booleans. If you pass a JSON number &lt;code&gt;0&lt;/code&gt; to a naive Rust implementation, it evaluates to &lt;code&gt;true&lt;/code&gt; and renders the section! &lt;/p&gt;

&lt;p&gt;To fix this while keeping behavioral equivalence, I built a custom evaluator:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pub fn is_truthy(val: &amp;amp;Value) -&amp;gt; bool {
    match val {
        Value::Null =&amp;gt; false,
        Value::Bool(b) =&amp;gt; *b,
        Value::Number(n) =&amp;gt; n.as_f64().map_or(false, |f| f != 0.0 &amp;amp;&amp;amp; !f.is_nan()),
        Value::String(s) =&amp;gt; !s.is_empty(),
        Value::Array(a) =&amp;gt; !a.is_empty(),
        Value::Object(_) =&amp;gt; true,
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;
  
  
  2. Enforcing Zero Unsafe Code
&lt;/h3&gt;

&lt;p&gt;Many high-performance parsers use &lt;code&gt;unsafe&lt;/code&gt; raw pointers or unchecked indexing. I wanted this port to be 100% memory safe, so I put &lt;code&gt;#![forbid(unsafe_code)]&lt;/code&gt; at the very first line of &lt;code&gt;src/main.rs&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Turning unsafe into a &lt;strong&gt;hard compiler error&lt;/strong&gt; meant ensuring that all string building and token array traversals used standard safe primitives without sacrificing execution speed.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Dynamic Scope Walking
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;mustache.js&lt;/code&gt;, looking up a key in a nested section walks up the parent context stack dynamically. Translating this stack-walking logic into Rust without running into ownership and borrow-checker issues required carefully modeling scope lifetimes.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Secret Sauce: Jugaad Mode (&lt;code&gt;--jugaad&lt;/code&gt;)
&lt;/h2&gt;

&lt;p&gt;Standard template engines panic or crash when fed malformed input — like an unclosed tag or a missing section boundary. &lt;/p&gt;

&lt;p&gt;In production, a small syntax typo shouldn't take down an entire deployment pipeline. Inspired by the Indian philosophy of &lt;em&gt;jugaad&lt;/em&gt; (frugal, clever problem-solving), I added &lt;strong&gt;Jugaad Mode&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An opt-in pre-processor that auto-repairs unclosed tags and mismatched section boundaries on the fly.&lt;/li&gt;
&lt;li&gt;Outputs friendly diagnostic logs (&lt;code&gt;theek kar diya (fixed it)&lt;/code&gt;, &lt;code&gt;band kar diya (closed it)&lt;/code&gt;) while continuing execution cleanly.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Proving Equivalence: 30,000+ Fuzzing Runs
&lt;/h2&gt;

&lt;p&gt;To prove that &lt;code&gt;mustache-rs&lt;/code&gt; behaves 100% identically to &lt;code&gt;mustache.js&lt;/code&gt;, I built an automated differential fuzzer in Node.js (&lt;code&gt;fuzz/run_fuzz.js&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;The fuzzer generated random templates and JSON context data, feeding them to both engines simultaneously and byte-comparing the outputs. Over a continuous test run of &lt;strong&gt;30,567 iterations&lt;/strong&gt;, the engines produced &lt;strong&gt;0 output divergences&lt;/strong&gt;!&lt;/p&gt;




&lt;h2&gt;
  
  
  Reflections &amp;amp; Thank You!
&lt;/h2&gt;

&lt;p&gt;Building this over 72 hours was an incredible experience. Huge shoutout to the &lt;strong&gt;Port Mortem 2026 organizers and the Hackathon Raptors community&lt;/strong&gt; for putting together such an inspiring, high-quality hackathon track. It forced me to think like a compiler engineer and build a tool I'll actually use in my daily workflow.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌐 &lt;strong&gt;Live Browser Verification Portal&lt;/strong&gt;: &lt;a href="https://gargee-508.github.io/Jugaad_Mustache/" rel="noopener noreferrer"&gt;https://gargee-508.github.io/Jugaad_Mustache/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🐙 &lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href="https://github.com/gargee-508/Jugaad_Mustache" rel="noopener noreferrer"&gt;gargee-508/Jugaad_Mustache&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>hackathonrapters</category>
      <category>portmortem</category>
    </item>
  </channel>
</rss>
