المترجم الفوري (Just In Time Compiler - JIT)

📘 درس Visual Basic - المترجم الفوري (Just In Time Compiler - JIT)


🔹 ما هو JIT؟

المترجم الفوري (Just In Time Compiler - JIT) هو جزء من بيئة التشغيل CLR يقوم بترجمة الكود الوسيط (Intermediate Language - IL) إلى كود أصلي قابل للتنفيذ على جهازك أثناء وقت التشغيل.


💡 لماذا نستخدم JIT؟

لأنه يسمح بتحسين أداء التطبيق عن طريق ترجمة الكود عند الحاجة فقط، مما يقلل حجم الملفات ويوفر مرونة أكبر في تشغيل البرامج على منصات مختلفة.


✅ أنواع JIT

  • Normal JIT: يترجم الكود عند استدعائه لأول مرة ويتم الاحتفاظ بالكود الأصلي في الذاكرة لاستخدامه لاحقًا.
  • Econo JIT: يترجم الكود ويزيله من الذاكرة بعد تنفيذه لتقليل استهلاك الذاكرة.
  • Pre-JIT: يترجم كل الكود عند تحميل التطبيق، ويُعرف أيضًا بـ NGen.

💻 مثال مبسط يوضح دور JIT

عند تشغيل هذا المثال، يقوم JIT بتحويل الكود إلى تعليمات مناسبة لجهازك لحظة التنفيذ.


Module Program
    Sub Main()
        Dim result As Integer = Multiply(4, 5)
        Console.WriteLine("النتيجة: " & result)
    End Sub

    Function Multiply(a As Integer, b As Integer) As Integer
        Return a * b
    End Function
End Module

🌍 English Explanation

The Just In Time Compiler (JIT) is a part of the CLR that translates Intermediate Language (IL) code into native executable code on your machine at runtime.

💡 Why Use JIT?

Because it optimizes application performance by translating code only when needed, reducing file size and providing flexibility to run programs on different platforms.

✅ Types of JIT

  • Normal JIT: Translates code the first time it is called and keeps the native code in memory for future calls.
  • Econo JIT: Translates code and removes it from memory after execution to save memory.
  • Pre-JIT: Translates all code when the application is loaded (also known as NGen).

💻 Simple Example Illustrating JIT Role

When you run this example, JIT converts the code into instructions specific to your machine at runtime.


Module Program
    Sub Main()
        Dim result As Integer = Multiply(4, 5)
        Console.WriteLine("Result: " & result)
    End Sub

    Function Multiply(a As Integer, b As Integer) As Integer
        Return a * b
    End Function
End Module

تعليقات

المشاركات الشائعة من هذه المدونة

1.1 SQL Introduction

Entity Framework - ما هو ORM؟ ونبذة عن Dapper وNHibernate

LINQ Concat Method