perry README

项目的 README,来自 github.com/PerryTS/perry。合并为一个 markdown 文件:README.md。

Perry

Write TypeScript. Ship native. Everywhere.

Perry compiles the TypeScript you already write into real machine-code executables — for macOS, Windows, Linux, iOS, Android, watchOS, and TV. No Node.js to install. No Electron to bundle. No runtime at all. Just a binary. (The same codebase can also target the web, emitted as JavaScript or WebAssembly.)

Latest release Join the Perry Discord community

Website · Documentation · Showcase · Examples

perry compile src/main.ts -o myapp
./myapp    # a standalone native binary — ~34 KB for hello world

The language you know. The deployment you wish it had.

Millions of developers write TypeScript every day — but shipping it has always meant shipping a JavaScript engine: a Node install on every server, ~100 MB of embedded runtime per CLI, or a whole browser engine per desktop app. Perry removes the engine. SWC parses your code, LLVM compiles it to machine code, and you get what systems languages get: instant cold starts, tiny self-contained binaries, real threads — without leaving TypeScript.

Perry Node.js Bun Electron
What you ship One native binary, from ~34 KB Your code + a Node install One binary embedding the JS engine App bundle with a browser engine
Execution Ahead-of-time machine code JIT JIT JIT
Cold start Instant — no engine to boot, no warmup Engine boot + warmup Engine boot + warmup Browser boot
Native UI (no WebView) ✅ AppKit, UIKit, Android Views, Win32, GTK4 — — Chromium
iOS · Android · watchOS · TV ✅ from the same codebase — — —
Multicore Real OS threads, data-race-safe at compile time worker_threads workers processes

Table describes Perry's native targets. --target web / --target wasm emit JavaScript / WebAssembly that runs in the browser rather than as a native binary.

Performance

Ahead-of-time machine code means no engine boot and no JIT warmup — and on measured workloads, real multiples over the JS runtimes. Highlights from our open benchmark harnesses (Apple M1 Max, medians of repeated runs):

Workload Perry Node.js Bun Rust
Image convolution (4K, 5×5 Gaussian) 354 ms 1,207 ms — 3.4× slower 915 ms — 2.6× slower 392 ms
Fibonacci (recursive calls) 309 ms 987 ms — 3.2× slower 518 ms — 1.7× slower 316 ms
JSON pipeline (100 records) 39 ms 144 ms — 3.7× slower 51 ms — 1.3× slower 34 ms
JSON pipeline (500k records, 108 MB) 1,649 ms 1,010 ms — 1.6× faster 647 ms — 2.5× faster 604 ms
Object allocation (1M objects) 2 ms 8 ms — 4× slower 6 ms — 3× slower <1 ms
Array write (10M elements) 3 ms 9 ms — 3× slower 6 ms — 2× slower 7 ms
Peak memory (JSON pipeline) 3.5 MB 36 MB — 10× more 11 MB — 3× more 1.2 MB

Look at the Rust column again: on convolution, fibonacci, and the array-write loop, TypeScript compiled with Perry runs even with — or ahead of — Rust. And Electron isn't in the table because it doesn't compete here: it ships a whole browser engine per app, where a comparable Perry app is a single-digit-MB native binary.

Sources: convolution & JSON from the systems-language report — pinned to 7beb3a50ca, the last revision whose artifact contains these values; the copy at HEAD was regenerated in #7641 on a host where the harness clock was invalid and now reads 0.0 ms in every timing cell (see this PR). Re-pin to main once it is regenerated. Fibonacci, object allocation & array write from the polyglot sweep (Perry default mode, no fast-math).

We publish everything, including the workloads where V8's JIT still beats us — no cherry-picked table can survive an open harness. Run it yourself: ./benchmarks/run_public_baseline.sh (methodology).

The full published suite, generated from the artifact — including the rows we lose

Generated from benchmarks/results/public-node-bun-v1.json at Perry commit b77aba63433b. Lower wall-clock median is better; every row includes complete raw samples and passed correctness checks. Medians within 5% of a peer count as a tie with it.

Benchmark Perry Node.js Bun Result What it tests
modulo_loop 93 ms 95 ms 95 ms tie Integer-modulo accumulation loop (microbenchmark)
method_calls 35 ms 11 ms 8 ms loss vs both Class method dispatch
closure 47 ms 49 ms 49 ms tie Closure creation and invocation
binary_trees 13 ms 6 ms 6 ms loss vs both Tree allocation and traversal
string_concat 6 ms 31 ms 5 ms mixed String append loop
prime_sieve 6 ms 5 ms 5 ms loss vs both Sieve of Eratosthenes
mandelbrot 25 ms 24 ms 29 ms mixed Complex-number iteration
matrix_multiply 19 ms 33 ms 33 ms win vs both Matrix multiplication
json_roundtrip 144 ms 379 ms 219 ms win vs both Parse and stringify ~1 MB JSON

Why developers pick Perry

Get started in 60 seconds

# Install (macOS · Linux · Windows)
npm install -g @perryts/perry     # or: brew install perryts/perry/perry
                                  # or: winget install PerryTS.Perry

# Create and run a project
perry init my-app && cd my-app
perry run .

npm packages and ES modules work as you'd expect:

import fastify from 'fastify';

const app = fastify();
app.get('/api/users', async () => [{ id: 1, name: 'Alice' }]);
app.listen({ port: 3000 }, () => console.log('Listening on :3000'));
perry compile src/main.ts -o api && ./api    # one binary — no node_modules on the server

Same code, other platforms: --target ios, --target android, --target web… full list in the platforms guide. APT, Scoop, install script, and source builds are in the installation guide; run perry doctor to verify your setup.

Built with Perry

Real products, shipping today:

Project What it is Platforms
Bloom Engine Native TypeScript game engine — Metal, DirectX 12, Vulkan, OpenGL macOS, Windows, Linux, iOS, tvOS, Android
Mango Native MongoDB GUI — ~7 MB binary, sub-second cold start macOS, Windows, Linux, iOS, Android
Hone AI-powered native code editor with terminal, Git, and LSP macOS, Windows, Linux, iOS, Android, Web
dB Meter Real-time sound level measurement at 60 fps iOS, macOS, Android

Mango — native MongoDB GUI built with Perry Hone — AI code editor built with Perry

More in the showcase — built something with Perry? Open a PR and add it.

Documentation

Everything else lives in the docs:

Community

Perry is built in the open — come say hi:

Privacy

Telemetry is opt-in: nothing leaves your machine unless you explicitly enable it in ~/.perry/config.toml, and PERRY_NO_TELEMETRY=1 (or CI=true) always wins. What can be sent is anonymous and redacted — never your source, paths, or project names. Inspect it any time with perry doctor, and see exactly what's in the payload in the privacy & telemetry docs.

Sponsors

Perry's development is backed by our sponsors. 🙏

Skelpo — premium sponsor

💎 Skelpo — Premium Sponsor

Want to support Perry and see your logo here? Get in touch via perryts.com.

License

MIT

perry (PerryTS/perry)

正在搜索数据库…

这是什么?Perry 能把你已经编写的 TypeScript 或 JavaScript 直接编译成原生机器码可执行文件,支持 macOS、Windows、Linux、iOS、Android、watchOS 和 TV 平台。它使用 SWC 解析代码、LLVM 生成机器码,因此无需附带 Node.js 运行时或 Electron 打包文件。
它是我要在 Node 中导入的库,还是独立的编译器工具链?它是一个独立的提前编译器和命令行工具链,而不是可以在 Node 应用中用 require() 调用的库。它使用 SWC 解析代码,通过 LLVM 生成原生机器码,最终产出一个自包含的二进制文件。
如何安装 Perry 并编译我的第一个程序?可以通过 APT、Scoop、安装脚本安装,或按照安装指南从源代码构建。然后对入口文件运行编译器;`perry doctor` 用于检查环境配置是否正确,`--target ios`、`--target android` 和 `--target web` 可切换输出平台。
运行编译后的二进制文件需要安装 Node.js 吗?不需要。编译后的 Perry 程序完全没有运行时,不依赖 Node、Bun,也不内嵌浏览器引擎,只需可执行文件本身即可运行。
我现有的 Node 代码和 npm 包能直接在 Perry 下运行吗?大多数常用的 Node API 都能工作:Node 官方测试套件中约 97% 的用例在 53 个 node: 模块上通过,另有大约 50 个热门 npm 包(如 Fastify、Express、mysql2 和 ioredis)也可运行。但这并非完全兼容 Node,而且支持的 TypeScript 语法有已记录的限制。
我究竟可以把应用发布到哪些平台?使用同一套代码,你可以面向 macOS、iOS、iPadOS、visionOS、tvOS、watchOS、Android、Wear OS、Windows、Linux 以及 Web/WASM 进行构建。它提供类似 SwiftUI 的 API,并会在各平台编译为真正的原生控件。
Perry 会向我的电脑之外发送任何遥测或数据吗?遥测功能仅为可选启用:除非你在 ~/.perry/config.toml 中自行开启,否则不会发送任何内容;即使发送,载荷也是匿名且经过脱敏的,绝不会包含你的源代码或项目名称。
生成的二进制文件有多小?一个“hello world”程序编译后约为 330 KB;像 Mango MongoDB 图形界面这样的真实应用打包后约 7 MB,冷启动时间不到一秒。
Perry 如何让多核代码保持安全?它提供由真正的操作系统线程支持的 parallelMap、parallelFilter 和 spawn,并且编译器会拒绝共享的可变状态,使数据竞争在编译阶段就报错,而不是在运行时崩溃。
Perry 比 Node.js 或 Bun 快多少?在公开的基准测试套件中,Perry 在字符串拼接和 JSON 往返等负载上都优于两者,某些情况下比 Node 快 3 倍以上;不过 V8 的 JIT 在少数大数据场景中仍然更快。作者会公布完整结果,包括落后的部分。
人们已经用 Perry 构建了哪些类型的应用?展示过的项目包括 Bloom Engine(基于 Metal、DirectX12 和 Vulkan 的原生游戏引擎)、Mango(原生 MongoDB 图形界面)、Hone(AI 驱动的代码编辑器)和 dB Meter(实时声级应用),它们都基于同一套代码发布到多个原生平台。
有哪些类似的项目?scriptc, whisker, exact, nsh, goose, Tov, Kof4j, swift
作者
PerryTS
大小
548.4 MB
星标
5.1K
时长
10个月
提交 · 90 天