#성능 튜닝 가이드
버전: 0.33.0 최종 업데이트: 2026-03-15 적용 대상: ranvier-core, ranvier-runtime 카테고리: Operations
#1. 릴리스 프로파일
Ranvier는 워크스페이스 Cargo.toml에 최적화된 릴리스 프로파일을 제공합니다:
[profile.release]
lto = true # Link-Time Optimization (크로스 크레이트 인라이닝)
strip = true # 바이너리에서 디버그 심볼 제거
codegen-units = 1 # 최대 최적화를 위한 단일 코드 생성 단위
opt-level = 3 # 최대 최적화 수준빌드 명령: cargo build --release
예상 효과:
- 바이너리 크기: ~30-50% 감소
- 런타임 지연시간: ~5-15% 개선 (LTO가 크로스 크레이트 인라이닝을 가능하게 함)
- 빌드 시간: ~2-3배 증가 (런타임 성능을 위한 트레이드오프)
#2. Bus 리소스 접근 패턴
Bus는 O(1) 타입 인덱스 리소스 조회를 위해 AHashMap<TypeId, Box<dyn Any>>를 사용합니다.
#모범 사례
반복 조회 대신 참조를 캐싱하세요:
// ❌ 나쁜 예 — 다중 조회
async fn handle(&self, input: Input, _: &Res, bus: &mut Bus) -> Outcome<Output, Error> {
let db = bus.read::<DbPool>().unwrap();
do_query(db).await;
let db = bus.read::<DbPool>().unwrap(); // 불필요한 조회
do_another_query(db).await;
// ...
}
// ✅ 좋은 예 — 단일 조회, 참조 재사용
async fn handle(&self, input: Input, _: &Res, bus: &mut Bus) -> Outcome<Output, Error> {
let db = bus.read::<DbPool>().unwrap();
do_query(db).await;
do_another_query(db).await;
// ...
}가능하면 컴파일 타임 접근을 위해 Res (리소스 튜플)를 사용하세요:
// Res 튜플을 통해 전달된 리소스는 오버헤드가 없음 — HashMap 조회 없음
impl Transition<Input, Output, Error, (DbPool, Config)> for MyStep {
async fn handle(&self, input: Input, (db, config): &(DbPool, Config), bus: &mut Bus) -> Outcome<Output, Error> {
// db와 config에 직접 접근 — Bus 조회 불필요
}
}#3. Axon 회로 최적화
#핫 경로를 짧게 유지하세요
// ✅ 좋은 예 — 일반적인 경우에 최소한의 단계
let axon = Axon::new("fast-path")
.then(Validate) // 빠른 검사
.then(Process) // 메인 로직
.then(Respond); // 직렬화
// ❌ 피해야 할 예 — 핫 경로에 불필요한 단계
let axon = Axon::new("slow-path")
.then(LogEntry) // 미들웨어로 이동
.then(Validate)
.then(AuditTrail) // 비동기 후처리로 이동
.then(Process)
.then(LogExit) // 미들웨어로 이동
.then(Respond);#횡단 관심사에는 미들웨어 레이어를 사용하세요
로깅, 메트릭, 감사를 Axon 단계가 아닌 Tower 레이어로 이동하세요.
#4. 컴파일 시간 팁
# 빠른 피드백을 위해 cargo check (코드 생성 없음) 사용
cargo check --workspace
# 공유 컴파일 캐시를 위해 sccache 사용
cargo install sccache
export RUSTC_WRAPPER=sccache
# 메모리 부담을 줄이기 위해 병렬 컴파일 제한
export CARGO_BUILD_JOBS=4
# 증분 컴파일 사용 (디버그에서 기본값)
export CARGO_INCREMENTAL=1#5. 종속성 기능 감사
컴파일 범위를 최소화하기 위해 종속성 기능을 정기적으로 감사하세요:
# 미사용 종속성 찾기
cargo install cargo-udeps
cargo +nightly udeps
# 함수별 바이너리 크기 분석
cargo install cargo-bloat
cargo bloat --release --crates#6. 참고 자료
- 보안 강화 가이드
- Ranvier 설계 원칙
- Rust Performance Book