智能工具库

用 Rust 重写 Copilot 运行时:AI 辅助开发与性能飞跃

用 Rust 重写 Copilot 运行时:AI 辅助开发与性能飞跃

GitHub 将 Copilot 运行时从 TypeScript 迁移到 Rust,AI 辅助编写了 80 万行代码,实现了性能数量级提升和多产品统一架构。

2026-09-17 0来源:GitHub Blog

用 Rust 重写 Copilot 运行时:AI 辅助开发与性能飞跃

GitHub Copilot 不仅仅是一个代码补全工具,它背后支撑着一个庞大的 Agent Runtime(代理运行时)。这个运行时被嵌入在 GitHub Copilot CLI、Copilot App 以及各种 SDK 中,为微软、GitHub 及生态系统的众多产品提供底层智能支持。

在过去,这个运行时是基于 TypeScript 和 Node.js 构建的。但随着其功能日益复杂,性能和扩展性开始成为瓶颈。最近,GitHub 完成了一次巨大的技术重构,将这个运行时彻底重写为了超过 80 万行生产级代码的 Rust。

重构规模:AI 赋能的代码编写

这次重构的规模令人咋舌。作为技术负责人,Stephen Toub 在 2026 年 9 月宣布,团队利用 GitHub Copilot 应用和 CLI,将整个运行时重写为了 Rust。

关键数据:

  • 代码量: 超过 80 万行生产级 Rust 代码。
  • AI 参与度: AI 编写了绝大部分代码。
  • 开发流程: 代码通过 128 个 Pull Request(PR)逐步合并到主分支,而非一次性切换。

实用解读: 这对开发者最大的启示在于,AI 已经具备了编写复杂生产级代码的能力。原本需要整个团队耗费 1-2 年才能完成的重任,在 AI 的辅助下,由一名开发者在几个月内完成,且团队其他成员可以并行扩展运行时的功能。这种协作模式展示了未来软件开发的范式转变。

性能与架构的必要性

为什么必须迁移到 Rust?主要原因在于 TypeScript/Node.js 栈在特定场景下的局限性。

  1. 服务器密度与内存: Copilot 运行时不仅服务于 CLI,还服务于 VS Code、Visual Studio、Excel、Outlook 等众多产品。这些产品对启动速度、响应能力以及内存占用有极高的要求。Node.js 的内存开销相对较大,难以满足高密度的服务器部署需求。
  2. 架构解耦: 最初的 CLI(终端界面)与运行时代码耦合较深。为了提供 SDK,团队不得不在逻辑上对架构进行调整,而 Rust 的内存安全特性和高性能,使其成为解决这些遗留架构问题的理想选择。

重构带来的红利

这次从 TS 到 Rust 的迁移并非没有风险,但结果是积极的:

  • 性能提升: 运行时的性能得到了数量级的提升。
  • 快速迭代: 增量的 PR 合并方式意味着问题可以在早期被发现和修复,避免了单点故障。

总结: GitHub Copilot Runtime 的 Rust 重构不仅是一次技术栈的升级,更是一次关于 AI 辅助编程可行性的有力证明。对于开发者而言,这意味着我们可以利用 AI 处理繁重的底层重构工作,从而专注于核心业务逻辑的创新。

The Copilot runtime architecture before and after the Rust rewrite, showing the old SDK-to-CLI process boundary and the new in-process and out-of-process hosting paths.

TypeScript fell to zero while production Rust rose to approximately 830,000 lines and Rust unit tests to approximately 469,000 lines.

Timeline from May 12 through August 21 showing 128 port pull request merges sized by changed lines and 135 public CLI releases; the largest port changes cluster near completion of the port.

Timeline of 128 landed port pull requests from May through August, progressing from small foundational components to larger orchestration and session work.

Temporary Rust N-API exports and their TypeScript call sites grew during the incremental port, then declined as callers moved to Rust and the temporary interop surface disappeared.

Of 2,639 human-authored messages, 31.0% focused on review, testing, and CI; 17.4% challenged technical or design decisions; and 15.0% pushed for completeness.

本文基于 GitHub Blog 的公开内容,由 AI 辅助整理改写后发布。

原标题:Migrating the GitHub Copilot runtime to Rust, using Copilot

阅读原文