핵심 요약
WASM Component Model 2.0 GA. WIT(WebAssembly Interface Types)로 Rust·Go·Python·JS 컴포넌트 직접 호출. 사내 4개 언어로 작성한 라이브러리 통합 18개월 운영, 빌드 -42%, 보안 격리 활용.
1. WIT — interface 정의
// world.wit
package myorg:utils@1.0.0
interface text {
normalize: func(s: string) -> string
count-words: func(s: string) -> u32
}
world utils {
export text
}
언어 중립 interface. Rust·Go·Python으로 각각 구현 가능, 호출 측은 동일.
2. Rust 구현 → JS 호출
// Rust
wit_bindgen::generate!({ world: "utils" });
struct MyText;
impl Guest for MyText {
fn normalize(s: String) -> String { s.trim().to_lowercase() }
}
// JS
import { text } from './utils.wasm'
console.log(text.normalize(' HELLO ')) // 'hello'
3. 사용 사례
- 고성능 image processing — Rust 컴포넌트, Node 백엔드에서 호출
- 수학·통계 — Python 컴포넌트, Go API 호출 가능
- 보안 격리 — 신뢰 못 하는 user-supplied code를 sandbox 안에서 실행
- Edge runtime — Cloudflare/Fastly에서 WASM 컴포넌트 직접 실행
4. 성능 — Rust 컴포넌트 vs native Rust
| 작업 | Native | WASM 컴포넌트 |
|---|---|---|
| 텍스트 처리 1MB | 8ms | 14ms |
| 이미지 리사이즈 5MB | 120ms | 180ms |
| Init time | 0ms | 3ms |
30~50% 느리지만 격리·이식성 이득이 큰 경우 합리적 trade-off.
5. 함정
- Stream/async 타입 — 2.0에서 정식, 1.x에서는 다르게 표현, 마이그레이션 필요
- Resource 패턴 — opaque handle, 메모리 누수 가능, drop 명시
- Toolchain 호환 — wit-bindgen 버전 통일 필수, language별 generator
- Debugging — 컴포넌트 안의 panic이 host에 명확히 전달 안 되는 경우, structured error 정의

댓글 0