Go と Rust の違い
Goは運用しやすいサーバー・CLI、Rustは安全性と性能が必要なシステム寄りの開発に向きます。
- Go: API、CLI、インフラツール
- Rust: CLI、WASM、低レイヤー、高性能処理
| 観点 | go | rust |
|---|---|---|
| 得意領域 | API、CLI、運用 | 安全性、性能、低レイヤー |
| 学習 | 初期は入りやすいが実務では設計力が必要 | 周辺知識も含めて学ぶ |
| 判断 | 目的に合えば最初の候補 | チームや実行環境で選ぶ |
追加調査で押さえる実務ポイント
GoとRustはどちらもnative executableを作れる現代的な言語ですが、最適化する対象が異なります。Goはgarbage collection、goroutine、channel、標準library、単純なbuildでnetwork serviceとteam開発を速くします。Rustはownershipとborrow checkerによりGCなしでmemory safetyを強制し、低レイヤー制御と予測可能なresource管理を重視します。性能の一般論ではなく、latency、memory、開発速度、unsafe境界で選びます。
先に結論
| 条件 | 選びやすい言語 |
|---|---|
| Web API・network service | Go |
| CLIを短期間で開発 | Go |
| system component | Rust |
| memory safety + no GC | Rust |
| 学習・採用速度 | Go |
| embedded・Wasm | Rust |
| 大量goroutine | Go |
| C/C++置換 | Rust |
実行モデル
Go
sourceをnative binaryへcompileし、runtimeがGC、goroutine scheduler、stack growth等を管理します。
Rust
sourceをnative binaryへcompileし、ownership・lifetimeをcompile時に検査します。通常runtime GCはありません。
最小例
Go
package main
import "fmt"
func main() {
fmt.Println("hello")
}
Rust
fn main() {
println!("hello");
}
Memory管理
| 観点 | Go | Rust |
|---|---|---|
| 基本 | GC | ownership |
| allocation | escape analysis等 | explicit type/ownership |
| pause | GC影響あり | GCなし |
| use-after-free | runtime管理 | compile-time防止 |
| 学習 | 比較的容易 | ownership習得必要 |
Concurrency
Goはgoroutineとchannelを言語・runtimeへ統合します。RustはOS thread、async runtime、channel、mutexをtype systemのSend・Syncと組み合わせます。
Goのgoroutineは軽量ですが、raceが自動的に消えるわけではありません。go test -race等を使います。
Rustはdata raceを多くの場面でcompile時に防ぎますが、deadlockやlogic raceは残ります。
Error handling
Goは複数戻り値のerrorを明示的に扱います。RustはResult<T, E>と?で伝播します。
Buildと配布
Goは単一binaryを作りやすく、cross compileも比較的単純です。RustはCargo ecosystemが強力ですが、native dependencyとtarget toolchainを確認します。
性能比較の注意
benchmarkはworkload、allocator、GC setting、I/O、compiler version、libraryで変わります。自社taskでp50/p95 latency、memory、CPU、binary size、build timeを測ります。
Team判断
Goが向く
- 多人数backend
- microservice
- infrastructure tool
- simple deployment
- standardized style
- fast onboarding
Rustが向く
- parser
- database engine
- network proxy
- embedded
- browser component
- security-sensitive native code
両方使う
control planeをGo、performance-critical data planeをRustにする構成もあります。FFIよりprocess/API境界の方が保守しやすい場合があります。
次に読む
参考リンク
- go.dev - Go公式
- go.dev - Effective Go
- doc.rust-lang.org - Rust ownership
- doc.rust-lang.org - Rust concurrency