Hacker News 中文摘要

RSS订阅

Perry利用SWC与LLVM将TypeScript直接编译为可执行文件 -- Perry Compiles TypeScript directly to executables using SWC and LLVM

文章摘要

Perry是一个将TypeScript编译为原生应用的平台,支持多平台开发且无需运行时依赖。它能生成高性能、体积小(2-5MB)的独立可执行文件,采用直接编译技术(SWC解析+LLVM代码生成),具有确定性构建特性,并提供丰富的标准库支持。

文章总结

Perry:将TypeScript编译为原生应用的全栈解决方案

核心特性

  • 跨平台支持:可将TypeScript代码编译为macOS、iPadOS、iOS、Android等10+平台的本地GUI/CLI应用
  • 极致性能:v0.5.306版本采用分代GC和惰性JSON解析,基准测试超越Node.js和Bun
  • 无运行时依赖:生成2.3MB独立可执行文件,无需Node.js/V8等运行时环境

技术优势

  1. 编译架构

    • 使用SWC进行语法解析
    • 通过LLVM生成优化机器码
    • 编译过程跳过JavaScript中间层
  2. 标准库支持

    • 原生实现fs/path/crypto等Node.js核心模块
    • 提供25+原生UI组件(按钮/文本框/滚动视图等)
    • 内置30+本地化npm包(mysql2/axios/dayjs等)
  3. 开发体验

    • 确定性构建:相同输入始终生成相同二进制
    • 真多线程支持:提供parallelMap/spawn等线程API
    • 编译时插件系统:依赖项转为原生函数调用

平台适配

| 平台 | 框架 | 状态 | |------------|------------|--------| | macOS/iOS | AppKit | 稳定 | | Android | Views | 稳定 | | Windows | Win32 | 稳定 | | Web | JavaScript | 稳定 |

性能对比

| 指标 | Perry | Node.js | 优势倍数 | |---------------|--------|---------|----------| | 启动时间 | 1ms | 30ms | 30x | | JSON处理 | 75ms | 394ms | 5.3x | | 对象创建 | 1ms | 11ms | 11x | | 二进制大小 | 2-5MB | 80MB | 16-40x |

工作流程

```typescript // hello.ts console.log("Hello, World!")

// 编译命令 $ perry compile hello.ts -o app → 生成2MB原生可执行文件 ```

发布支持

  • 自动化应用签名(支持App Store/Play Store)
  • 多平台UI测试验证
  • 开源项目免费使用

(注:保留核心技术参数和对比数据,精简重复的功能描述和营销性表述,优化表格呈现方式)

评论总结

以下是评论内容的总结,按主要观点分类呈现:

【技术可行性争议】 1. "无运行时"声明存疑: - "the claim of 'no runtime' is a bit dubious... you're statically linking a full, modern UI library into every app?" (evil_buzzard) - "The site boasts no runtime dependencies but clearly it’s going to need things like a garbage collector" (afavour)

  1. 性能与语义取舍:
  • "Perry uses NaN-boxing... 1.24 billion wasted instructions traced specifically to NaN-boxing" (madanparas)
  • "You cannot get C-level performance without dropping TypeScript semantics" (madanparas)

【AI生成内容担忧】 1. 代码质量质疑: - "Calling a couple million lines of ai written Rust 'stable software'" (koteelok) - "the pacing of the commits is eerily fast... makes me dubious how much accountability the creators have" (smasher164)

  1. 文档问题:
  • "the text on the site is very clearly AI generated" (afavour)
  • "dozens of packages and slop markdown files... makes me trust the project less" (hypendev)

【技术实现探讨】 1. 编译器工作原理: - "How is this possible, even with something as simple as interface method calls" (jeswin) - "explain how it works on the website... are those techniques really sufficient to express TS?" (jeswin)

  1. 实际应用限制:
  • "requiring JS runtime for something as basic as an Express web server" (ventana)
  • "what is the practical difference between a js file and the same file with .ts extension" (curtisblaine)

【潜在价值肯定】 1. 创新性认可: - "Fascinating... Cross-platform Typescript is a really interesting proposition" (afavour) - "A very interesting project because I always thought TypeScript should be natively compiled" (satvikpendem)

  1. 性能优势:
  • "0 ms Startup time... no initialization of any other libraries needed?" (Reubend)
  • "the performance seems cool" (hypendev)

【项目管理问题】 1. 维护性担忧: - "How do you guarantee stability? If there's a memory corruption error in the GC" (smasher164) - "jsruntime was removed one week ago, but the error messages not updated" (tacone)

  1. 安全风险:
  • "Shell injection?" (mittermayr) 引用curl示例代码

【行业现象批评】 - "Why is this on the front page? Isn't it just more vibe-coded garbage" (chenzhekl) - "all vibe-coded web-site cards so stupidly identical" (lenkite)

总结呈现了支持、质疑和中立三种立场,保留了原始评论的关键引用,并突出了技术实现、AI生成内容和项目管理三个核心争议点。每个观点都配有代表性的原始评论作为佐证。