# JIT style dynamic compiler

**URL:** <https://internals.rust-lang.org/t/jit-style-dynamic-compiler/13346>\
**Category:** language design\
**Created:** [November 7, 2020, 5:43am UTC](https://internals.rust-lang.org/t/jit-style-dynamic-compiler/13346 "2020-11-07T05:43:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![VaibhavDS19](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/vaibhavds19/32/7310_2.png) [@VaibhavDS19](https://internals.rust-lang.org/u/VaibhavDS19)\
**Post date:** [November 7, 2020, 5:43am UTC](https://internals.rust-lang.org/t/jit-style-dynamic-compiler/13346/1 "2020-11-07T05:43:46Z")

</div>

I have seen some stuff like Java or C# compiler running some optimizations at compile time. Can something similar be added, like a macro? Like unsafe but with dynamic compiling for purely that section? It might improve performance in some of those cases.

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [November 7, 2020, 12:56pm UTC](https://internals.rust-lang.org/t/jit-style-dynamic-compiler/13346/3 "2020-11-07T12:56:42Z")

</div>

MIRI is an interpreter, not a JIT.

> [@VaibhavDS19](#):
>
> I have seen some stuff like Java or C# compiler running some optimizations at compile time.

Running optimizations at compile time is exactly what Rust does as AOT compiler.

> [@VaibhavDS19](#):
>
> Like unsafe but with dynamic compiling for purely that section? It might improve performance in some of those cases.

What do you mean with "like unsafe"?

---

<div class="post-metadata">

**Author:** ![bheisler](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bheisler/32/3189_2.png) [@bheisler](https://internals.rust-lang.org/u/bheisler)\
**Post date:** [November 7, 2020, 1:37pm UTC](https://internals.rust-lang.org/t/jit-style-dynamic-compiler/13346/4 "2020-11-07T13:37:30Z")

</div>

I think what is being suggested here is a block that instructs the compiler to compile the contained code to some form of bytecode or other IR that would then be JIT-compiled at runtime.

Such a thing would take a great deal of work, but there's no fundamental reason why it couldn't be done. It wouldn't even need to be built into the compiler; procedural macros could accomplish this, combined with a JIT-compiler built as a crate.

If OP wants this, I would recommend building it yourself; I expect it will be very difficult to persuade others to do the large amount of work involved on a volunteer basis.

---

<div class="post-metadata">

**Author:** ![atagunov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/atagunov/32/5877_2.png) [@atagunov](https://internals.rust-lang.org/u/atagunov)\
**Post date:** [November 7, 2020, 1:53pm UTC](https://internals.rust-lang.org/t/jit-style-dynamic-compiler/13346/5 "2020-11-07T13:53:05Z")

</div>

Rust has been jokingly referred to as "the new C++". I guess the reasons there are no Jit compilers for Rust are similar to why there are no Jit compilers for C++ or C.

---

<div class="post-metadata">

**Author:** ![bascule](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bascule/32/3057_2.png) [@bascule](https://internals.rust-lang.org/u/bascule)\
**Post date:** [November 7, 2020, 3:38pm UTC](https://internals.rust-lang.org/t/jit-style-dynamic-compiler/13346/6 "2020-11-07T15:38:47Z")

</div>

For incorporating runtime information into how Rust code is optimized, check out [profile-guided optimization](https://doc.rust-lang.org/rustc/profile-guided-optimization.html).

That's not a JIT, of course, but it can get you some benefits similar to ones a JIT gives you, namely runtime analysis of what optimizations should be performed.

Edit: as it were, there's a new Inside Rust post on PGO:

> **[Exploring PGO for the Rust compiler | Inside Rust Blog](https://blog.rust-lang.org/inside-rust/2020/11/11/exploring-pgo-for-the-rust-compiler.html)**
>
> Want to follow along with Rust development? Curious how you might get involved? Take a look!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [February 5, 2021, 3:38pm UTC](https://internals.rust-lang.org/t/jit-style-dynamic-compiler/13346/7 "2021-02-05T15:38:52Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
