Porffor: A from-scratch ahead-of-time JS engine
Porffor is an experimental JavaScript engine that compiles code to WebAssembly or native binaries, achieving significant size and performance improvements, but is currently intended for research purposes only.
Read original articlePorffor is an experimental JavaScript engine, compiler, and runtime designed to compile JavaScript code to WebAssembly (Wasm) or native binaries ahead-of-time (AOT). Currently, it is intended for research purposes and is not suitable for serious use due to its limitations. The engine's Wasm output is significantly more efficient than existing JavaScript to Wasm projects, being 32 times smaller and 18 times faster than Javy, with sizes reduced from approximately 1.3MB to around 40KB and performance improvements from 70ms to 4ms.
In terms of native compilation, Porffor achieves over 1000 times smaller binary sizes, reducing from about 90MB to less than 50KB, and decreases memory usage by more than 40 times, from 50MB to around 1MB, while also enhancing performance by up to three times. Porffor is designed with safety in mind, as it compiles to Wasm and is built using a memory-safe language. It is developed from scratch with AOT principles, relying solely on a JavaScript parser and supporting TypeScript input without requiring a cumbersome transpilation step. The engine is tested against the official ECMAScript conformance test suite, Test262, to monitor its conformance progress with each commit. Users can experiment with Porffor online or install it locally via npm.
Related
Orb: Write WebAssembly with Elixir
Orb leverages Elixir's ecosystem to simplify WebAssembly writing, offering features like composable modules, Hex package manager, ExUnit testing, macros, and syntax highlighting. It enables Elixir code compilation to .wasm, supports reusable modules, and integrates existing Elixir libraries for MIME tasks, showcasing flexibility in WebAssembly development.
Show HN: Simulating 20M Particles in JavaScript
This article discusses optimizing JavaScript performance for simulating 1,000,000 particles in a browser. It covers data access optimization, multi-threading with SharedArrayBuffers and web workers, and memory management strategies.
Dynamic Translation of Smalltalk to WebAssembly
The article explores Smalltalk code translation to WebAssembly (WASM) within the Catalyst project. It details levels of Smalltalk, JavaScript, and WASM, focusing on direct Smalltalk to WASM optimization. A new translator, WATCompiledMethodTranslator, aids in this process, exemplified by a Smalltalk expression conversion. Creation of a WASM module for Smalltalk methods is explained, highlighting performance advantages and potential future comparisons with dynamic JS translations. Collaboration in the Smalltalk community is encouraged for further advancement.
Show HN → Parallel DOM: Upgrade your DOM to be multithreaded
Parallel DOM accelerates web apps by parallelizing heavy DOM tasks. It integrates easily, runs React components concurrently, and ensures security through sandboxed iframes. Users can self-host or deploy with Vercel.
Baby's Second WASM Compiler
A new wasm compiler named zest is under development for 2024, focusing on quality and speed enhancements. It supports various features and employs a tree structure for expressions, emphasizing efficiency and simplicity.
- Excitement about Porffor's potential, especially with the main developer committing full-time to the project.
- Concerns regarding performance limitations of JavaScript and the challenges of maintaining compatibility with fast-evolving standards like TypeScript and V8.
- Comparisons to other JavaScript engines, particularly Static Hermes and QuickJS, highlighting differences in output capabilities and design approaches.
- Curiosity about the handling of runtime features like `eval` and the implications for performance and security.
- General interest in the future of JavaScript engines and their ability to compile to native binaries or WebAssembly.
The really cool optimizations come from compiling TypeScript, or something close to it. You could use types to get enormous gains. Anything without typing gets the default slow JS calls. Interfaces can get reduced to vtables or maybe even straight calls, possibly on structs instead of maps. You could have an Int and Float type that degrade into Number that just sit inside registers.
The main problem is that both TS and V8 are fast-moving, non-standard targets. You could only really do such a project with a big team. Maintaining compatibility would be a job by itself.
If we could bundle everything to native that would completely change the game since as good as bun's cold start is, you can't beat running straight native with a small binary.
I've spent a bit of time trying to review each, so hopefully this analysis will be useful for some readers. What are the main commonalities and differences between Static Hermes and Porffor?
* They both aim for JS test262 conformance [1]
* Porffor supports both Native and Wasm outputs while Static Hermes is mainly focused on Native outputs for now
* Porffor is self-hosted (Porffor is written in pure JS and can compile itself), while Static Hermes relies on LLVM
* Porffor currently doesn't support async/promise/await while Static Hermes does (with some limitations)
* Static Hermes is written in C++ while Porffor is mainly JS
* They both support TypeScript (although Static Hermes does it through transpiling the TS AST to Flow, while Porffor supports it natively)
* Static Hermes has a fallback interpreter (to support `eval` and other hard-to-compile JS scenarios), while Porffor only supports AOT compiling (although, as I commented in other thread here, it maybe be possible to support `eval` in Porffor as well)
In general, I'm excited to see if this project can gain some traction so we can speed-up Javascript engines one the Edge!
Context: I'm Syrus, from Wasmer [3][1] https://github.com/facebook/hermes/discussions/1137
If some change were required which introduced a regression on some Test262 tests, it could cause the version number to regress as well. This means Porffor cannot have both a version number which increases monotonically and the ability to introduce necessary changes which cause Test262 regressions
[0] https://github.com/CanadaHonk/porffor?tab=readme-ov-file#ver...
I have been working on providing quickjs with more node compatible API through llrt [1] for embedding into applications for plugins.
> 1+1
2
> help
Uncaught ReferenceError: help is not defined at exports.<computed> [as main] (file:///opt/homebrew/lib/node_modules/porffor/compiler/wrap.js:494:19) at REPLServer.run (file:///opt/homebrew/lib/node_modules/porffor/runner/repl.js:98:27) at bound (node:domain:432:15) at REPLServer.runBound [as eval] (node:domain:443:12) at REPLServer.onLine (node:repl:927:10) at REPLServer.emit (node:events:532:35) at REPLServer.emit (node:domain:488:12) at [_onLine] [as _onLine] (node:internal/readline/interface:416:12) at [_line] [as _line] (node:internal/readline/interface:887:18)
Any language that allows generating and interpreting its own code at runtime will have the "eval problem". From some other comments here, it sounds like Porffor's solution is to simply ignore it.
It was called hiphop-php, then they eventually gave up, before creating hhvm on a complete new concept.
I wont be surprised to see a SPA framework that uses Porffor once it is more mature, or even the major ones using it as part of their tooling.
WASM is the next step after SPA's essentially.
If you have never touched Blazor, I recommend you check it out via youtube video if you don't do any C#, it is impressive. Kudos to Microsoft for it. I have had 0 need or use for JavaScript since using it.
[0] https://bun.sh/
import * as squint_core from 'squint-cljs/core.js'; console.log("hello");
Related
Orb: Write WebAssembly with Elixir
Orb leverages Elixir's ecosystem to simplify WebAssembly writing, offering features like composable modules, Hex package manager, ExUnit testing, macros, and syntax highlighting. It enables Elixir code compilation to .wasm, supports reusable modules, and integrates existing Elixir libraries for MIME tasks, showcasing flexibility in WebAssembly development.
Show HN: Simulating 20M Particles in JavaScript
This article discusses optimizing JavaScript performance for simulating 1,000,000 particles in a browser. It covers data access optimization, multi-threading with SharedArrayBuffers and web workers, and memory management strategies.
Dynamic Translation of Smalltalk to WebAssembly
The article explores Smalltalk code translation to WebAssembly (WASM) within the Catalyst project. It details levels of Smalltalk, JavaScript, and WASM, focusing on direct Smalltalk to WASM optimization. A new translator, WATCompiledMethodTranslator, aids in this process, exemplified by a Smalltalk expression conversion. Creation of a WASM module for Smalltalk methods is explained, highlighting performance advantages and potential future comparisons with dynamic JS translations. Collaboration in the Smalltalk community is encouraged for further advancement.
Show HN → Parallel DOM: Upgrade your DOM to be multithreaded
Parallel DOM accelerates web apps by parallelizing heavy DOM tasks. It integrates easily, runs React components concurrently, and ensures security through sandboxed iframes. Users can self-host or deploy with Vercel.
Baby's Second WASM Compiler
A new wasm compiler named zest is under development for 2024, focusing on quality and speed enhancements. It supports various features and employs a tree structure for expressions, emphasizing efficiency and simplicity.