THE SUMMARYAI-generated
Key Concepts:
- WebAssembly (Wasm)
- Ahead-of-Time (AOT) Compilation
- Just-in-Time (JIT) Compilation
- JavaScript (JS) Engine
- Dynamic Typing
- Type Inference
- Partial Evaluation
- WebAssembly Garbage Collection (WasmGC)
- TC39
- Porfor (Compiler Kit for JavaScript)
1. Introduction and Guest Introduction
- The podcast "Web Assembly Unleashed" discusses news and views about WebAssembly.
- Joel Moses hosts the podcast with Chris Fallon as co-host and Matt Yakabuchi as a regular.
- Oliver Medhurst, an ex-Mozilla engineer, is introduced as a guest. He is known in the JavaScript/ECMAScript community and is working on Porfor, a compiler kit for JavaScript that can AOT compile JavaScript to WebAssembly.
2. WebAssembly Community Updates
- Chris Fallon notes that the WebAssembly ecosystem is maturing, with technologies like garbage collection reaching implementation phases.
- Zigg is re-engineering its async.io layer with WebAssembly as a first-class citizen.
3. Ahead-of-Time (AOT) Compilation Explained
- AOT compilation involves compiling source code on the developer's machine and shipping a binary to users, unlike JIT compilation where compilation happens on the user's machine.
- JavaScript AOT compilation is tricky because JavaScript is a dynamic language, making static analysis difficult. String concatenation and integer addition can look the same, depending on runtime data.
4. Why Use Ahead-of-Time (AOT) Compilation?
- AOT is useful in environments where JIT is not allowed (e.g., embedded devices, game consoles) for security reasons.
- AOT can provide better performance than interpreters in such environments.
- AOT allows creating native binaries for JavaScript applications (e.g., CLI apps) without shipping large runtimes like Node.js. AOT can result in binaries less than 1MB.
- AOT can reduce cold start times in cloud offerings like AWS Lambda, where starting a JavaScript runtime can take hundreds of milliseconds.
5. The Challenges of Dynamic Typing in JavaScript
- JIT compilers observe program execution to optimize based on runtime types.
- JavaScript's dynamic types make static analysis difficult.
- JIT compilers can specialize code on the fly (e.g., optimizing a function for integers if it's always called with integers).
- Monomorphism (calling a function with the same type consistently) can significantly improve performance.
- AOT compilation cannot do dynamic observation and must rely on static analysis. Incorrect type assumptions in AOT can lead to crashes.
6. Porfor's Approach to Type Specialization
- Porfor uses type inference to analyze types ahead of time.
- The compiler is cautious and only optimizes when it's certain about types.
- Function arguments are typically hard to infer unless there's good interprocedural analysis.
- Porfor focuses on low-level WebAssembly instruction-by-instruction optimization.
- Partial evaluation is used for optimizations like dead code elimination.
7. Performance and Use Cases of Porfor
- Porfor supports JS to WebAssembly and JS to native compilation. Native compilation is faster, but WebAssembly offers portability.
- Porfor can be used to run website plugins with better security through WebAssembly sandboxing.
- It can also be used in hosting environments that are optimized for WebAssembly.
- Porfor does not bundle an interpreter, resulting in smaller binaries (10-30 times smaller than with an interpreter) and better performance.
8. Conformance and Language Support
- Porfor currently supports about 60% of the JavaScript language, based on the specification tests.
- The short-term goal is to enable CLI apps with small (1MB) binaries.
- QuickJS is a JavaScript interpreter, but Porfor has shown to be faster in some benchmarks.
9. Building a JavaScript Engine from Scratch
- Development starts with easier features and gradually adds more complex ones.
- A major target is self-hosting, where Porfor can compile itself.
- Built-in APIs (e.g., array.push, Date) are written in TypeScript and compiled to WebAssembly.
- Temporal (a newer date/time proposal) is not a current target due to limited browser support.
10. Community Reaction and Project Status
- The JavaScript community has shown positive interest in Porfor.
- The project is currently in pre-alpha, with usability targeted for 2025.
- The compiler passes less than 40% of the JavaScript specification tests.
- Stability (fixing memory leaks and crashes) is a key focus.
- A target use case is AWS Lambda, where response times are limited to 500 milliseconds.
11. WebAssembly Garbage Collection (WasmGC)
- The WebAssembly GC proposal allows using the host-side GC.
- Oliver envisions a configuration setting to choose between no GC, full zone GC, or WasmGC.
12. Community Contributions and Contact
- Bug reports are valuable contributions.
- GitHub and Discord are used for communication. GitHub is better for organization, while Discord is useful for quick help.
13. WebAssembly to C Compilation
- Porfor ships with a WebAssembly to C engine (Wasm2C).
- It allows naming locals and optimizing C code for better performance.
- WasmGC may not be supported in the C backend.
14. Target Audience and Use Cases
- Interest comes from both JavaScript developers looking to target WebAssembly and WebAssembly developers looking to support JavaScript.
- Use cases include cloud platforms that only accept WebAssembly files and applications where reverse engineering needs to be prevented.
15. WebAssembly Proposals and Desired Features
- Porfor focuses on common WebAssembly proposals and avoids draft ones.
- A desired feature is a way to duplicate a value on the stack without using a local variable.
16. Advice for Ahead-of-Time Compiler Developers
- It's often better to try things out rather than spending too much time theorizing.
- Iterate and experiment to see what works in practice.
17. The Origin of the Name "Porfor"
- "Porfor" is Welsh for purple, chosen because no other JavaScript engine is purple-colored.
18. Conclusion
- Oliver Medhurst has made significant progress on Porfor, a JavaScript compiler kit for WebAssembly.
- The community is encouraged to provide bug reports and feedback.
- The podcast emphasizes the importance of AOT compilation and unleashing the power of WebAssembly.
AI summaries can miss context or contain errors. Check important details against the original video.





