Porffor:一个从头开始的实验性超前 JS 引擎
Porffor: A from-scratch experimental ahead-of-time JS engine

原始链接: https://porffor.dev/

Porffor 是一种新颖的 JavaScript 引擎,可将 JavaScript 代码预编译到 WebAssembly 或本机提前 (AOT) 中,与传统的 JavaScript 到 WebAssembly 方法相比,在速度和大小方面有显着改进。 其紧凑的 WebAssembly 输出(约 40kb)导致执行速度快了 18 倍(从约 70 毫秒降至 4 毫秒),与其他类似项目(如 Javy 约 1.3)相比,其大小约小 32 倍。 mb)。 通过提前编译 JavaScript,Porffor 无需打包运行时即可生成实际的本机二进制文件,从而显着减小二进制大小(比典型解决方案小 1000 倍以上,例如 90mb 缩小到 50kb 以下)。 Additionally, its memory footprint is drastically reduced by more than 40 times (from approximately 50mb to merely 1mb)。 Porffor 通过直接提供对 TypeScript 输入的支持来利用其 AOT 设计,从而消除了通常与 TypeScript 相关的繁琐的转译步骤。 此外,该项目包括一个简单的命令行界面(CLI),并使用官方 ECMAScript 一致性测试套件(Test262)进行了测试,以确保兼容性和准确性。 用户甚至可以通过在线游乐场使用浏览器尝试 Porffor,或者通过 npm install 在本地计算机上进行设置。

一种称为“Prolog”的类型检查机制已被开发出来,以确保编程指令在给定环境中安全运行。 它检查程序执行期间数据类型的转换。 例如,如果将两个浮点数相加,它可以确保结果运算产生另一个浮点数。 值得注意的是,此类型系统识别“顶级”类型,该类型充当系统中的最高级别类型,表示长层次结构或双层次结构的顶部,因为这些是多值构造。 这个概念在过去很实用,特别是当系统是 32 位时。 然而今天,由于技术的变化,它似乎不再那么重要了。 JavaScript 运行时开发人员对模拟 WebAssembly (Wasm) 的兴趣日益浓厚,该项目让许多人想起了 Facebook 的 Static Hermes 项目,该项目旨在增强 React Native 应用程序在各种平台上的性能。 Static Hermes 和 Porffor 是两个具有相似目标但又表现出不同特征的著名项目。 两者都致力于与 ECMAScript 标准 Test262 兼容。 然而,虽然 Porffor 支持生成适合本机和 WebAssembly 应用程序的输出,但 Static Hermes 目前主要专注于生成本机输出。 此外,Porffor 独立运行,因为它完全用 JavaScript 编写,而 Static Hermes 则依赖 LLVM 来完成编译任务。 在对 Promise 和异步函数等高级功能的支持方面也存在区别。 虽然 Porffor 缺乏这样的功能,但 Static Hermes 提供了它,但有一定的限制。 至于语言选择,Static Hermes 使用 C++,而 Porffor 主要使用 JavaScript 基础。 尽管如此,两者都适应 TypeScript 的使用,尽管它们的处理方式不同 - Static Hermes 将 TypeScript 文件转换为 Flow,而 Porffor 本身支持 TypeScript。 最后,虽然 Static Hermes 包含一个后备解释器来解决 eval 等棘手的 JavaScript 实例,但 Porffor 仅限于提前 (AOT) 编译。 展望未来,这些工具的开发可能会带来更快的 JavaScript 引擎,使其与 Microsoft Blazor 平台等现代技术相比更具竞争力。 这一快速进展为单页应用程序拥抱 Porffor 或观察其他 WebAssembly 工具接管传统 JavaScript 角色提供了可能性。 如果您之前从未探索过 Blazor,请考虑通过 YouTube 视频了解一下
相关文章

原文
Porffor

Porffor is a unique JS engine/compiler/runtime, compiling JS code to WebAssembly or native ahead-of-time.
It is limited for now; intended for research, not serious use!

Porffor's WebAssembly output is much faster and smaller compared to existing JS -> Wasm projects. This is because Porffor compiles JS AOT instead of bundling an interpreter.

  • Wasm size: 32x smaller than Javy (~1.3MB -> ~40KB)
  • Wasm perf: 18x faster than Javy (~70m -> ~4m)

Due to compiling JS ahead-of-time, Porffor can compile to real native binaries without just packaging a runtime like existing solutions. This leads to:

  • Binary sizes over 1000x smaller (~90MB -> <50KB)
  • Memory usage over 40x less (~50MB -> ~1MB)
  • Performance up to 3x faster

Porffor is safe as it compiles to Wasm (and then native). It is also written in a memory safe language (JS).

Porffor is written from the ground-up with AOT in mind instead of being based on any existing JS engine. The only dependency is a JS parser.

Porffor supports TypeScript input, no clunky transpiler step needed: just feed it a TS file.

Playground You can try Porffor here online or locally with npm i -g porffor@latest && porf

Target

Test262 Test262 is the official ECMAScript conformance test suite. Porffor is ran against it each commit to track conformance progress!

3 months

6 months

all-time

联系我们 contact @ memedata.com