<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Deepak Aravind on Medium]]></title>
        <description><![CDATA[Stories by Deepak Aravind on Medium]]></description>
        <link>https://medium.com/@aravindprodev?source=rss-35b5d5a808a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Y9AkzPAmPWpLys0p</url>
            <title>Stories by Deepak Aravind on Medium</title>
            <link>https://medium.com/@aravindprodev?source=rss-35b5d5a808a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 15:58:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aravindprodev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JIT and AOT — What are those]]></title>
            <link>https://medium.com/@aravindprodev/jit-and-aot-what-are-those-dbc7d06b61a2?source=rss-35b5d5a808a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbc7d06b61a2</guid>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[interpreters]]></category>
            <dc:creator><![CDATA[Deepak Aravind]]></dc:creator>
            <pubDate>Sat, 17 Aug 2024 07:12:07 GMT</pubDate>
            <atom:updated>2024-08-17T07:25:53.938Z</atom:updated>
            <content:encoded><![CDATA[<h3>JIT and AOT — What are those</h3><p>The heading “JIT and AOT — What are those” is what literally i asking myself during (and probably also after) writing this post</p><h4><strong>Very informal introduction (</strong><em>please skip, if you know basic understanding of compilers</em><strong>):</strong></h4><p>As we all know CPU tends to understand only a limited set of instruction to perform computation which are hard to comprehend due to its simplest grammar but with high number of instruction to perform even simple computation, so it always not best to write and read code in machine code(unless you are playing or debugging)</p><p>Yes, Machine code should be simplest as possible as CPU itself must not take larger amount of time to perform complex tasks such as parsing (, linking ?)</p><p>Then, we had compilers to solve this problem. Compiler accepts single (or multiple) languages. The language is consists of quite complex grammars, to make the instructions(program) simpler enough that human can understand (by naked eye). A program’s instruction should be part of given language’s grammar. Programming language are evolved from C and its family is mostly what we are using as modern programming language.</p><h3>JIT and AOT:</h3><p>Compilers translates this high level <em>language </em>to <em>machine code </em>, so that it can be executed. We solved the problem of writing machine code using <em>compilers . </em>Yes, first compiler of C is written in assembly by bare hand.</p><p>So, compilers comes with the cost of (may)expensive computation to translate the given language and also tries to do it efficiently(this makes even hard).</p><p><em>expensive computation on low-end devices == slow performance</em></p><p>Traditionally, a software is programmed, compiled (thankfully the creator has some high end system) and the bundled machine code (binary executable) is shared with the software’s target audience. So the target audience don’t need to perform the expensive computation and can easily execute the software without ease.</p><p>But the need of client side programming is emerged (for ex: js in browsers), so there is no compilation need to be done by the creator, just the source code can be shipped to the users. Then, the users need to compile and execute it. But we know that</p><p><em>expensive computation on low-end devices == slow performance</em></p><p>this makes the process of compiling slower in all users who has low end devices :(<br>For example: A software’s program codebase is consists of 500 files, so to compile them we need to traverse and process every 500 files. But in reality client side programming languages not always necessarily need those 500 source file’s machine code, where some can be invoked only later through some interactions. So compiling 500 files at a time could be lot of stress and also performing optimization on them could take even more time, to just start the application.</p><p>Enter JIT, stands for Just-in-Time compilation. JIT eliminates compiling every source files but compiles only the necessary parts of the application. And it would start execute them and then lazily it would try to translate the remaining files. This would not make the user wait for a long loading screen, but show something that it compiles and compiles remaining source code lazily.</p><p>Henceforth, we are taking Javascript as scenario for the JIT compilation in the browsers.<br>Since Javascript is developed and intended to run on client side through the browsers.<br>Browsers contains Javascript Engine (v8, spidermonkey, webkit specific to browsers- its worth for a separate blog) which can compile the js code lazily which known as interpreting.</p><p>The process of interpreting is performing JIT on the source code. The process of JIT involves several strategies (for ex: Inline Caching). These strategies are specific to the JS Engine, each may implement its own strategy to tackle the problem according to their Engine Implementation.</p><p>JIT heavily relies on heuristic approach, as it cannot able to generate entire program’s CFG or DFG since some parts of the program may not even interpreted. So it would make a <em>guess </em>on several things based on the existing execution, for ex: If a function is called more frequently it would try to cache it, rather translating to machine code every time. But this is a <em>rough guess</em> ,<em> </em>meaning it become wrong in the future, from the same example, after caching the function then the function may not even called, so then it would try to deoptimize it. So by doing this cycle again and again, <br>we may get a optimistic results but not all the time, it totally relies on the JIT strategy (and its implementation by the JS Engine) and the given source code.</p><p>v8 is the JS Engine used in chromium (chrome, brave) based browsers and also in standalone JS runtimes such as nodeJS, deno.<br>v8 tries to make JIT effectively, it has a two components known as Ignition, Turbo fan.</p><p>Ignition (<em>see more </em><a href="https://v8.dev/docs/ignition"><em>here</em></a><em>): <br></em>It is a component in v8, where the AST fed and it outputs a bytecode which is used internally by v8 further for producing machine code. To understand ignition’s bytecode see more <a href="https://medium.com/dailyjs/understanding-v8s-bytecode-317d46c94775">here</a>. It would try to cache the bytecode for given AST under certain circumstances (such as if it is frequently gets called)</p><p>Turbo Fan (<em>see more </em><a href="https://v8.dev/docs/turbofan"><em>here</em></a><em>):<br></em>It is also a part of v8, where the ignition’s bytecode is fed in and it emits the equivalent machine code for the given input. Turbo fan also tries to cache and optimize the machine code if the given ignition’s bytecode eligible to do so. Turbofan adapts a “Sea of Nodes” (see <a href="https://darksi.de/d.sea-of-nodes/">here</a>).</p><p>There is much more happens under the hood in v8, the above mentioned are just a few part of the process of successfully performing JIT.</p><p>AOT stands for Ahead-of-time Compilation, where it is what our traditional compilers do, it would generate the entire CFG and tries to do optimization (which might expensive) and emits the machine code. The optimization are done in levels in some compilers (gcc, dart), the more levels the more optimization can be done.</p><p>Dart is a programming language and its compiler is capable of performing both JIT and AOT compilation. AOT Compilation is a bit tricky as it would emit machine code consists of it pre-defined <a href="https://dart.dev/tools/dartaotruntime"><em>dartaotruntime </em></a>and aot snapshot (which is a IR <em>dartaotruntime</em> interprets) which is quite interesting to look. Similarly, deno also does this (See more <a href="https://docs.deno.com/runtime/manual/tools/compiler/"><em>here</em></a><em>)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbc7d06b61a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Benchmarking Cloudflare and Deno]]></title>
            <link>https://medium.com/@aravindprodev/benchmarking-cloudflare-and-deno-b4ee24e9b114?source=rss-35b5d5a808a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4ee24e9b114</guid>
            <category><![CDATA[cloudflare-workers]]></category>
            <category><![CDATA[deno]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloudflare]]></category>
            <dc:creator><![CDATA[Deepak Aravind]]></dc:creator>
            <pubDate>Fri, 30 Dec 2022 10:37:59 GMT</pubDate>
            <atom:updated>2022-12-30T10:44:02.644Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Everyone, Today as iam bored.. Just wanna see the performance differences between <strong>Cloud flare’ Workers</strong> and <strong>Deno Deploy.</strong></p><p>Let’s take a look what the heck are these…</p><p>What is Deno Deploy and Cloudflare Workers ?</p><p>Both are a commercial product or services, that it can run javascript or typescript in an isolated environment whenever it receives a request.</p><p>After the request end, that request’s process ends. And it wakes for another request.</p><p>This is shortly called <strong>Serverless</strong>. Also they are Edge Services. That means it provide the response from the closest server to the <em>user.</em></p><p>Since both has some similar characteristics, so it cant be compared.</p><p>But this is for just for exploring them.<br>Both are commonly referred as for Serverless Edge Function.<br>So the benching is simple,</p><p>For both a single route /hash is created as per its code design, and<br> /hash/:data<br> Here’s the data — path, is hashed ten times by SHA-512 (I know it doesn’t make sense).<br> This makes the program little computing.<br>After the creation of sources, the both sources will deployed in the services.</p><p>Here’s the Source File of both,</p><p>This is the common hashing function for both Services,</p><pre>async function specialHash(text: string) : Promise&lt;string&gt; {<br>        for(let i = 0; i &lt; 10; i++) {<br>        let hash = await crypto.subtle.digest({ name: &quot;SHA-512&quot;}, new TextEncoder().encode(text));<br><br><br>       let decoded =  [...new Uint8Array(hash)]<br>      .map(b =&gt; b.toString(16).padStart(2, &#39;0&#39;))<br>      .join(&#39;&#39;);<br><br>      text = decoded;<br>     }<br>        return text;<br>}</pre><p>And here the cloudflare worker, <strong>main.ts</strong> (It is pretty)</p><pre>export default {<br>        async fetch(<br>                request: Request,<br>                env,<br>                ctx<br>        ): Promise&lt;Response&gt; {<br>                const url = new URL(request.url);<br>                if(url.pathname.startsWith(&quot;/hash&quot;)){<br>                        const target = url.pathname.split(&#39;hash/&#39;)[1];<br>                        const hashed = await specialHash(target);<br>                        return new Response(`Hashed 10 times of ${target} is ${hashed}`);<br>                }<br>                return new Response(&quot;Nope&quot;);<br>        },<br>};</pre><p>Deno’s source also similar to this,</p><pre>import { serve } from &quot;https://deno.land/std@0.167.0/http/server.ts&quot;;<br><br>const handler = async (request: Request) =&gt; {<br>                const url = new URL(request.url);<br>                if(url.pathname.startsWith(&quot;/hash&quot;)){<br>                        const target = url.pathname.split(&#39;hash/&#39;)[1];<br>                        const hashed = await specialHash(target);<br>                        return new Response(`Hashed 10 times of ${target} is ${hashed}`);<br>                }<br>                return new Response(&quot;Nope&quot;);<br><br>}<br><br>serve(handler, { port: 8070});</pre><p>(Literally both are doing same things…)</p><p>After the creation of sources, the both sources will deployed in the services.</p><p>Used wrangler — CLI by CloudFlare for Workers,<br>Used deployctl — CLI by Deno for Deno Deploy.</p><p>The Sources are deployed now, its time to bench :)<br>Using Apache bench, we can make number of requests to a server and it will show the summary of request and response time between client and server.</p><p>This is my first benching experience, i don’t have that much knowledge on performance and analysis.</p><p>I used some random paragraph to test in both.</p><p>So First, I ran both the sites in browser (Brave) and took snapshot of response time.</p><p>Left Side is Deno, And Right is Workers..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dEnIRQ76UWr1UDeW05BJYA.png" /></figure><p>As you can see the response time of deno is <em>77ms </em>and the worker is <em>100ms.</em></p><p>Thats for a single request and lets see difference between them with a number of requests.</p><p>And now its time to see the main Bench, it took 1000 requests (this bench doesn’t make concurrent requests)</p><p>The result may shock you…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ujFgF4p44y33-h3o7WSoRw.png" /></figure><p>Left is Cloudflare and right is deno, here also deno has a smaller response time.</p><p>The analytics board of both…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nmDL7PZQwU0S9JaC-KeBfw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xAzY_vbBPAOUkTKVKtZlEA.png" /></figure><p>Also workers, were failed at some requests you can see that in above..</p><p>Here lets took some analysis here:<br>What workers have ?</p><p>It said it have direct V8 runtime that they run every Functions as Isolated.<br>It has many edge location than Deno, since all the servers are deployed at their own cloud.</p><p>What Deno Deploy have ?</p><p>As they said, it have a customized (optimized) deno runtime so i thought it will slower than Worker since it have Direct V8 runtime. But its not. So i guess the deno is written on rust. Maybe it helped it (i dont have that much<br> knowledge on performance).<br> It has just 35 edge servers. Also it is 35 edge servers are deployed on GCP, as they said.</p><p>Lastly, this is not meaningful comparison because both are created for a different scenario.<br>But just for exploring (to make fun) i benched this.</p><p>As a developer, both are provided a good interface to deploy them. I appreciate that because it not took much time to deploy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4ee24e9b114" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>