<?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 Shashank Sharma on Medium]]></title>
        <description><![CDATA[Stories by Shashank Sharma on Medium]]></description>
        <link>https://medium.com/@shashanksharma_87474?source=rss-984726a41fb8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0l32axv4lWA-DejZ.</url>
            <title>Stories by Shashank Sharma on Medium</title>
            <link>https://medium.com/@shashanksharma_87474?source=rss-984726a41fb8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:21:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shashanksharma_87474/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[Unlocking Performance Secrets: Unleashing the Power of JIT Compilation]]></title>
            <link>https://medium.com/@shashanksharma_87474/unlocking-performance-secrets-unleashing-the-power-of-jit-compilation-1082da911cb7?source=rss-984726a41fb8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1082da911cb7</guid>
            <category><![CDATA[jit-compilers]]></category>
            <dc:creator><![CDATA[Shashank Sharma]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 19:50:54 GMT</pubDate>
            <atom:updated>2024-04-17T19:50:54.017Z</atom:updated>
            <content:encoded><![CDATA[<p>This comprehensive guide delves into the world of Just-In-Time (JIT) compilation, a powerful technique that bridges the gap between the speed of compiled languages and the portability of interpreted languages. By understanding its inner workings, benefits, and challenges, developers can leverage JIT to create efficient and performant applications.<br>Traditional Compilation vs. Interpretation: Understanding the Foundations</p><p>Before exploring JIT, let’s solidify our grasp of traditional compilation and interpretation paradigms:</p><h3><strong>Traditional Compilation:</strong></h3><blockquote><strong>Preprocessing</strong>: Source code undergoes preparation (e.g., expanding macros, including headers) before translation.<br> <strong>Lexical Analysis</strong>: The code is broken down into basic building blocks (tokens) like keywords, identifiers, and operators.<br> <strong>Syntax Analysis</strong>: The parser verifies if the token stream adheres to the language’s grammar rules, constructing a parse tree that represents the code’s structure.<br> <strong>Semantic Analysis</strong>: Ensures type compatibility, identifies undeclared variables, and verifies the program’s overall meaning.<br> <strong>Intermediate Representation (IR) Generation</strong>: Often, an IR, a language-independent representation capturing the program’s essence, is created.<br> <strong>Code Generation</strong>: The IR is translated into machine code specific to the target processor architecture. This step involves instruction selection, register allocation, and optimization techniques for efficient machine code.<br><strong> Linking and Assembly</strong>: Multiple object files (containing machine code for specific source files) are combined, external symbol references are resolved, and the final executable is generated. An assembler might convert assembly code into machine code during this stage.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*6uYgLsZ95epvpO-dA8tkvA.png" /><figcaption><em>Figure 1 — Process of Compilation and Runtime Execution of Compiled Application, Source: Omer Iqbal, GeekcampSG.</em></figcaption></figure><h3>Interpretation: Where Portability Takes Center Stage</h3><p><em>Interpreted languages prioritize portability over raw speed. Their code is written in a human-readable format and translated into bytecode at runtime. This bytecode is then interpreted by a virtual machine (VM), a software layer that acts as an intermediary between the bytecode and the underlying hardware.</em></p><blockquote><strong>Bytecode Generation</strong>: Source code is translated into bytecode, a platform-independent intermediate representation designed for execution by a virtual machine (VM).<br><strong>Virtual Machine</strong> (VM): The VM acts as an intermediary between bytecode and the underlying hardware, interpreting bytecode instructions one by one and performing corresponding operations on the system.<br><strong>Just-In-Time (JIT) Compilation</strong> (Optional): Some interpreted languages leverage JIT compilation as an optimization technique. Frequently executed bytecode is dynamically translated into machine code for performance gains.</blockquote><h4><strong>Key Differences:</strong></h4><blockquote><strong><em>Execution Time</em></strong>: Compiled programs typically run faster due to bypassing interpretation.<br> <strong><em>Portability</em></strong>: Interpreted programs are more portable as bytecode can run on any platform with a compatible VM. Compiled programs require recompilation for different architectures.<br> <strong><em>Development Workflow</em></strong>: Compilation can introduce delays due to compilation time. Interpreted languages offer faster development turnaround as compilation happens at runtime.<br><strong><em> Memory Usage</em></strong>: Compiled programs might have a smaller footprint due to the absence of the VM layer.<br> <strong><em>Security</em></strong>: Security considerations can differ. Compiled code runs directly on the hardware, potentially offering a larger attack surface. Interpreted code might benefit from the VM acting as an abstraction layer.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*q4AjWVATFxzC13iKXu7J0A.png" /><figcaption><em>Figure 2— Process of Interpretation, Source: Omer Iqbal, GeekcampSG.</em></figcaption></figure><blockquote>Imagine editing a complex document. Compiled languages are like pre-compiled versions — optimized for speed but requiring a complete overhaul for even minor changes. Interpreted languages are like editable documents — flexible and portable but potentially slower. JIT compilation bridges this gap, offering the best of both worlds</blockquote><h3>Unveiling the Magic of JIT Compilation</h3><p>Now, let’s delve into the heart of JIT compilation:</p><p><strong><em>Initial Execution</em></strong>: When an interpreted program encounters frequently executed code blocks (e.g., methods or loops), the runtime environment identifies the bytecode for those blocks.<br><strong><em>Dynamic Translation</em></strong>: A specialized JIT compiler, integrated within the VM itself, translates the identified bytecode into machine code tailored to the processor architecture where the program is running. This machine code is optimized for the specific instruction set and capabilities of the hardware.<br><strong><em>Optimized Execution</em></strong>: The generated machine code is then directly executed by the CPU, bypassing the interpretation step entirely. This significantly improves the performance of frequently used code sections.<br><strong><em>Monitoring and Recompilatio</em></strong>n: The JIT compiler continuously monitors program execution to identify hot code paths, frequently executed sections that benefit most from compilation. Additionally, the runtime environment might employ heuristics to predict which code blocks are likely to become hot in the future, proactively compiling them for performance gains.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*atByOlWIX2HA7vAZ_eWOhw.png" /><figcaption><em>Figure 43— Application of JIT in Python, Source: Omer Iqbal, GeekcampSG.</em></figcaption></figure><p><strong>Benefits of JIT Compilation</strong>:</p><p><strong><em>Performance Enhancement</em></strong>: JIT compilation can dramatically improve the execution speed of interpreted languages, often approaching the performance of compiled languages for frequently executed code.<br><strong><em>Reduced Memory Footprint</em></strong>: By compiling only hot code paths, JIT compilers can reduce the overall memory footprint of the program compared to fully interpreting all bytecode.<br><strong><em>Improved Development Experience</em></strong>: Faster execution times during development iterations enhance the developer experience, allowing for quicker feedback loops.</p><p><em>Below is the comparison of CPython (interpreter) vs PyPy (JIT)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*m-ShcYG3S63oWga9fNrU_A.png" /><figcaption><em>Figure 4— Python Benchmarking, Source: </em><a href="https://pybenchmarks.org/u64q/python3.php">https://pybenchmarks.org/u64q/python3.php</a><em>.</em></figcaption></figure><h4><strong>Challenges of JIT Compilation:</strong></h4><p><strong><em>Increased Startup Time</em></strong>: The initial compilation of hot code paths can introduce a slight delay during program startup compared to pure interpretation.<br> <strong><em>Complexity</em></strong>: Implementing efficient JIT compilers is a complex task, requiring deep understanding of both the interpreted language and the target processor architecture.<br> <strong><em>Security Considerations</em></strong>: Machine code generation by JIT compilers necessitates careful security measures to prevent the introduction of vulnerabilities through malicious code injection.</p><h4><strong>Advanced Topics in JIT Compilation</strong></h4><p><strong><em>Compilation Levels</em></strong>: JIT compilers often employ different optimization levels, balancing compilation time with the generated code’s performance. Lower levels might prioritize faster compilation, while higher levels strive for maximum performance but incur greater compilation overhead.<br><strong><em>Deoptimization</em></strong>: In scenarios where assumptions made during initial compilation become invalid (e.g., due to dynamic code behavior), the JIT compiler might deoptimize the generated machine code and revert to interpretation for that particular code block.<br><strong><em>Ahead-Of-Time (AOT) Compilation</em></strong>: Some JIT compilers can perform a hybrid approach, pre-compiling a subset of the code during program installation or startup, further reducing runtime compilation overhead.</p><h4><strong>Conclusion</strong></h4><p>JIT compilation is a powerful technique that significantly enhances the performance of interpreted languages. Its ability to dynamically translate bytecode into optimized machine code offers a compelling balance between speed and portability. By understanding the core concepts, benefits, and challenges of JIT compilation, developers can leverage this technique to create efficient and performant applications in interpreted languages.</p><p>This in-depth exploration serves as a stepping stone for further exploration of advanced JIT compilation techniques and their implementation details within specific programming languages and virtual machines.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1082da911cb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>