C-to-Rust performance: cross-layer characterization and AI diagnosis

Migrating C code to Rust can improve software security, but performance implications remain difficult to assess. While Rust often claims to match C performance, runtime safety checks, compiler optimizations, and hardware microarchitecture interact in ways that complicate diagnosis.

Researchers conducted a systematic cross-layer characterization of 12 benchmarks comprising C implementations and their Rust counterparts. The study found that runtime safety checks do not necessarily dominate performance overhead, as compiler and microarchitectural optimizations often mitigate their costs. Across 8 of the 12 benchmarks, at least one Rust implementation performed within 10% of its C counterpart or outperformed it.

FerroScope: AI-assisted performance debugger

Motivated by the complexity of cross-layer interactions, the team introduced FerroScope - an AI-assisted performance debugger that integrates source-level analysis, compiler optimization remarks, dynamic instruction traces, and hardware performance counters. FerroScope correlates evidence across these layers to identify potential causes of performance differences and produces evidence-supported explanations.

Testing showed FerroScope reproduces manual findings while providing more precise explanations in several cases. For example, it identifies compiler optimizations inhibited by redundant bounds checks and distinguishes implementation-level overhead from micro-architectural effects.

Diagnosis-guided compiler optimization

Researchers observed that performing safety checks inside hot loops was expensive and that current compiler passes are unable to hoist these checks to the loop preheader despite it being theoretically possible. They developed an LLVM compiler pass that hoists provably redundant bounds checks out of loops through guarded loop versioning.

The pass preserves Rust's observable panic behavior by retaining the original loop as a fallback when preheader checks cannot establish safety. Removing redundant checks enables subsequent LLVM optimizations that were previously inhibited, including loop unrolling and conditional-move conversion.

Evaluation showed the pass reduces Selection Sort's overhead from 2.95 to 1.00 relative to C, and improves Merge Sort from 1.43 to 0.91 relative to C.

Practical implications for C-to-Rust migration

Together, the results demonstrate how cross-layer performance characterization and AI-assisted diagnosis can guide safety-preserving compiler optimizations for efficient C-to-Rust migration. Developers rewriting legacy C codebases can use these techniques to maintain or improve performance while gaining Rust's memory safety guarantees.

The framework establishes that understanding performance regressions requires reasoning across multiple abstraction layers, from language-level constructs to compiler-generated instructions and their interactions with hardware microarchitecture.