Hacker News 中文摘要

RSS订阅

Nanobrew:与brew兼容的最快macOS包管理器 -- Nanobrew: The fastest macOS package manager compatible with brew

文章摘要

nanobrew是专为macOS设计的最快包管理器,采用Zig语言编写。其核心优势在于极速安装,热安装仅需3.5毫秒,比Homebrew快7000倍。通过并行依赖解析、流式SHA256验证和APFS克隆技术实现高效运作,支持快速安装(如jq仅需1.1秒)、列表管理和自我更新功能。

文章总结

nanobrew —— 速度最快的macOS软件包管理器

nanobrew是一款专为macOS设计的极速软件包管理器,采用Zig语言编写。

核心优势

  • 极速安装:热安装仅需3.5毫秒
  • 性能碾压:比Homebrew快7,000倍,甚至比echo命令更快
  • 一键安装:支持通过curl快速安装

性能对比

测试环境:Apple Silicon芯片,macOS 15系统

| 任务/场景 | Homebrew耗时 | nanobrew耗时 | 速度提升 | |----------------|-------------|-------------|---------| | tree(0依赖)冷安装 | 8.99秒 | 1.19秒 | 7.6倍 | | wget(6依赖)冷安装 | 16.84秒 | 11.26秒 | 1.5倍 | | ffmpeg(11依赖)热安装 | ~24.5秒 | 3.5毫秒 | 7,000倍 |

技术亮点

  1. APFS克隆文件:利用macOS系统调用实现零磁盘开销
  2. 全并行处理:下载、解压、依赖解析全程并发
  3. 原生HTTP客户端:取代curl子进程,减少进程创建
  4. 内容寻址存储:SHA256去重,避免重复下载
  5. 单一静态二进制:仅2MB大小,无运行时依赖

工作原理

  1. 并行依赖解析
  2. 流式下载与校验
  3. 内容寻址存储
  4. APFS克隆部署
  5. 二进制链接

使用示例

bash $ nb install jq # 安装软件包 $ nb list # 查看已安装包 $ nb update # 自我更新

该项目基于Homebrew的软件生态构建,采用Apache 2.0开源协议。

GitHub仓库 | 性能测试

评论总结

以下是评论内容的总结:

1. 兼容性问题 - 主要观点:许多评论者质疑该工具与Homebrew的兼容性,特别是其不执行Ruby代码的特性 - 关键引用: - "If it doesn’t ever execute Ruby: it cannot be compatible with Homebrew" (mikemcquaid) - "Homebrew formulae are written in Ruby...Do they use some kind of Ruby parser?" (maxloh)

2. 速度与兼容性的权衡 - 主要观点:部分用户认为兼容性比速度更重要,而另一些用户则赞赏速度优化 - 关键引用: - "Compatibility is more important than speed in this case" (drob518) - "This is a great trend...the Bun-ification of every package manager" (manlymuppet)

3. 安装和管理问题 - 主要观点:用户关注实际使用中的安装和管理细节 - 关键引用: - "Does it reinstall postgres for every package install?" (an0malous) - "what happens if I remove the tool? will I still be able to use Homebrew?" (marksully)

4. 与其他工具的比较 - 主要观点:用户将该工具与zerobrew等其他替代品进行比较 - 关键引用: - "It might be good to explain how this differs from zerobrew" (luizfelberti) - "I tried zerobrew...installed packages to a different directory" (alsetmusic)

5. 基础设施依赖风险 - 主要观点:评论者指出该工具对Homebrew基础设施的隐性依赖可能带来风险 - 关键引用: - "implicitly relies on Homebrew's CDN, CI, packaging infrastructure" (mikemcquaid) - "The risk is fragility when the host infrastructure changes" (peytongreen_dev)

6. 特定使用场景 - 主要观点:部分用户发现了该工具的特定用途 - 关键引用: - "especially to use only with casks now that Homebrew has removed support..." (pxc) - "What would be great is a system that doesn't cut off support for older machines" (ryandrake)