quickbeam  by elixir-volt

JavaScript runtime for the BEAM

Created 1 month ago
347 stars

Top 80.0% on SourcePulse

GitHubView on GitHub
Project Summary

This project provides a JavaScript runtime integrated directly into the Erlang VM (BEAM), enabling seamless execution of JavaScript code alongside Elixir/Erlang applications. It targets Elixir developers seeking to leverage JavaScript for web APIs, server-side rendering, or sandboxed execution, offering a powerful bridge between the two ecosystems with a built-in TypeScript toolchain and native DOM support.

How It Works

QuickBEAM runs JavaScript runtimes as BEAM GenServers, managed by OTP supervision trees. It facilitates bidirectional communication via message passing and handler functions (Beam.call, Beam.send), allowing JavaScript to invoke Elixir functions and access OTP libraries. The runtime uses QuickJS as its JavaScript engine and integrates with native C libraries like lexbor for a spec-compliant DOM, enabling direct manipulation and querying from Elixir. It supports dynamic context creation and pooling for efficient, high-concurrency JavaScript execution.

Quick Start & Requirements

  • Installation: Add {:quickbeam, "~> 0.7.1"} to your Elixir project's dependencies.
  • Prerequisites: Requires Zig 0.15+ (automatically installed by Zigler or can be provided system-wide).
  • Quick Start:
    {:ok, rt} = QuickBEAM.start()
    {:ok, 3} = QuickBEAM.eval(rt, "1 + 2")
    
  • Documentation: The README serves as the primary documentation.

Highlighted Details

  • BEAM Integration: JavaScript can call Elixir functions and access OTP libraries through configurable handlers.
  • Built-in TypeScript: Features a TypeScript toolchain (via OXC Rust NIFs) for direct evaluation, transformation, minification, and bundling without Node.js.
  • Native DOM: Leverages the lexbor C library for a full, spec-compliant DOM, allowing Elixir to query and manipulate it directly using Floki-compatible terms.
  • Context Pools: Efficiently manages thousands of JavaScript contexts using a small number of runtime threads, ideal for high-concurrency scenarios like LiveView.
  • Granular API Loading: Runtimes can load specific API groups (e.g., :fetch, :dom) to minimize memory footprint.
  • Node.js Compatibility: Implements core Node.js APIs, including fs, path, and os.
  • Bytecode Disassembly: Offers a tool to disassemble QuickJS bytecode into structured Elixir terms.

Maintenance & Community

Specific details regarding notable contributors, sponsorships, or community channels (e.g., Discord, Slack) are not provided in the README.

Licensing & Compatibility

  • License: MIT.
  • Compatibility: The MIT license permits commercial use and integration within closed-source projects.

Limitations & Caveats

A Zig 0.15+ dependency is required, which may add an extra setup step. Per-context memory limits and maximum reduction counts can be configured to prevent resource exhaustion, but exceeding these limits will interrupt JavaScript execution. While generally performant, Beam.callSync introduces a small overhead of approximately 5 μs.

Health Check
Last Commit

18 hours ago

Responsiveness

Inactive

Pull Requests (30d)
3
Issues (30d)
0
Star History
231 stars in the last 30 days

Explore Similar Projects

Starred by Yaowei Zheng Yaowei Zheng(Author of LLaMA-Factory), Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), and
7 more.

fragments by e2b-dev

0.1%
6k
Next.js template for AI-generated apps
Created 1 year ago
Updated 3 days ago
Feedback? Help us improve.