jit即时编译_JavaScript中的JIT:即时编译器

本文深入探讨了JavaScript中的JIT(Just-In-Time)编译器,解释了它如何提高代码性能,通过即时编译优化程序运行效率。
摘要由CSDN通过智能技术生成

jit即时编译

Have you ever wondered how web browsers or even the V8 for back-end runtimes (i.e Node and Deno) execute your JavaScript code? We all know that JavaScript is an interpreted language, but what exactly does that mean? And does that only mean one thing?

您是否曾经想过Web浏览器或什至用于后端运行时的V8(即Node和Deno)如何执行JavaScript代码? 我们都知道JavaScript是一种解释语言,但这到底意味着什么? 那仅意味着一件事吗?

Clearly, interpreted doesn’t mean compiled, but does that mean our code is not transformed in any shape or form during execution? Maybe that was true during the first years of JavaScript, but the truth is a lot more complex these days.

显然, 解释并不意味着编译,而是意味着我们的代码在执行过程中没有以任何形状或形式转换吗? 也许在JavaScript的最初几年是正确的,但如今的事实要复杂得多。

Tip: Use Bit (Github) to share, document, and manage reusable JS components from different projects. It’s a great way to increase code reuse, speed up development, and build apps that scale.

提示 :使用Bit ( Github )可以共享,记录和管理来自不同项目的可重用JS组件。 这是增加代码重用,加速开发并构建可扩展应用程序的好方法。

什么准时制? (What the JIT?)

Yeah, sorry, it was an easy joke, so I had to go for it.

是的,很抱歉,这是一个简单的玩笑,所以我不得不这样做。

On a more serious note, this is where the JIT compiler comes into play. JIT stands for Just In Time, meaning, unlike with a compiled language, such as C, where the compilation is done ahead of time (in other words, before the actual execution of the code), with JavaScript, the compilation is done during execution. I know, it sounds awkward, but trust me, it works!

更重要的是,这就是JIT编译器发挥作用的地方。 JIT代表Just In Time,这意味着与Java之类的已编译语言不同,JIT会提前(即在实际执行代码之前)使用JavaScript进行编译,而编译则是在执行期间完成的。 我知道,这听起来很尴尬,但是请相信我,它有效!

The great thing about a JIT compiler, is that once the code starts running, it is able to optimize it. And interestingly enough, given a complex enough code base, your code could be optimized differently for each user, depending on how each one uses your application. Let me explain.

关于JIT编译器的伟大之处在于,一旦代码开始运行,便可以对其进行优化。 有趣的是,给定足够复杂的代码库,可以根据每个用户使用应用程序的方式为每个用户优化代码。 让我解释。

JIT中有什么? (What’s in the JIT?)

Oh god, I can’t stop…

天哪,我无法停止……

So, every browser and runtime in general probably implements their own version of a JIT compiler, but the theory and the structure are usually the same across the board. A JIT compiler is supposed to follow the same structure:

因此,通常每个浏览器和运行时都可能实现自己的JIT编译器版本,但是其原理和结构通常都是相同的。 JIT编译器应该遵循相同的结构:

The monitor or profiler

监视器或探查器

While the code is executed by the interpreter, this component will profile it and keep track of how many times the different statements get hit. The moment that number starts growing, it’ll mark it a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值