arXiv:2610.23044cs.AIOct 2026

Manuscript Offprint

arXiv:2610.23044

Where Does the Performance Go? Understanding and Recovering Performance Regressions in C-to-Rust Translation

Zhiqiang Yuan, Chong Wang, Zhenhao Zhou, Junwei Liu, Xin Peng

Zhiqiang Yuan*, Chong Wang†, Zhenhao Zhou*, Junwei Liu*, and Xin Peng*

*Department of Computer Science, Fudan University, China

†Nanyang Technological University, Singapore

{zhiqiangyuan23, zhzhou24, jwliu24}@m.fudan.edu.cn

chong.wang@ntu.edu.sg

pengxin@fudan.edu.cn

Abstract—Rust is increasingly adopted as a memory-safe successor to C, and transpilers such as C2RUST can migrate entire C projects while preserving their behavior. Preserving behavior, however, does not guarantee preserving performance. We study this gap on 20 real-world C projects and their C2RUST translations. On the eight projects used for analysis, the translated Rust is more than 3% slower than the original C on 12 of 19 operations, by up to 62.2%. By comparing execution-cost profiles, optimized LLVM IR, and compiler optimization remarks across each C–Rust pair, we trace these slowdowns to nine recurring performance issues, spanning residual runtime work, missed compiler optimizations, and C-style source patterns, and derive an optimization direction for each. We then present PERFR, an LLM-based approach that encodes these issues as reusable optimization rules to recover the performance of translated Rust. PERFR profiles each project to locate hot functions and matches them against rule-specific patterns. The LLM then checks each rule's rewrite preconditions against the project context before rewriting, and a rewrite is kept only if it passes both functional and performance validation. On 41 operations from twelve held-out projects, PERFR preserves C outputs on all tested workloads and speeds up 40 operations over the C2RUST translations, 18 of which end up faster than the original C. It outperforms the general-purpose coding agent CODEX on 31 of the 37 operations where both preserve C outputs, and outperforms its own variant without rule guidance on 34 of the 41 operations.

I. INTRODUCTION

C remains widely used in systems and performance-critical software for its low-level control, predictable performance, and minimal runtime overhead [1], [2]. However, it is prone to memory-safety errors such as buffer overflows and use-after-free, which remain a major source of systems-software vulnerabilities [3], [4]. Rust mitigates these risks through ownership and borrowing while retaining low-level performance [5], [6], which has motivated efforts to migrate legacy C codebases to Rust, including Rust support in the Linux kernel [7]. As manual migration is costly and error-prone, automated C-to-Rust translation has become an active research area [8]–[11].

Existing approaches fall into two families. LLM-based translators aim to produce safer, more idiomatic Rust and increasingly use program analysis and project-level context to coordinate translations across components [12]–[16]. However, their outputs are not guaranteed to preserve behavior, a problem that worsens as project scale grows [12]–[14], [17]. Rule-based transpilers such as C2RUST instead apply deterministic syntax-directed rules that preserve source behavior, although their output retains C-oriented representations and extensive unsafe code [8]–[10], [18], [19]. Owing to this behavioral guarantee, rule-based output has become a common starting point for practical migration: it has been used in industrial projects [20], and recent hybrid approaches refine C2RUST-generated Rust with LLM-guided rewriting [21]–[23].

Recently, the performance of translated code has drawn attention [24]–[26]. Behavioral preservation does not imply performance preservation, and regressions after migration can offset the benefits of Rust in performance-critical software, where runtime efficiency is often a key reason for using C. The concern is most direct in rule-based output, which retains many C-style code patterns [18], [22] that can introduce runtime overhead. Xia et al. [24] evaluate C2RUST-generated programs on a synthetic C corpus and identify Relooper-induced code duplication as one source of runtime overhead, and RUSTY [27] avoids this control-flow expansion through a specialized translation scheme. General-purpose optimizers such as SemOpt [28] and MoST [29] instead guide LLM-based rewriting with reusable optimization knowledge.

These efforts leave translation-induced performance degradation only partially understood: existing measurements rely on synthetic programs and a single mechanism, while general optimization knowledge is not derived from the mechanisms that paired C–Rust analysis reveals. Consequently, three questions remain open: (1) whether and how much performance degrades after C-to-Rust translation in real-world projects; (2) which execution costs and code-level mechanisms explain such degradation; and (3) whether recurring mechanisms can be distilled into reusable rules for automated performance recovery.

To answer these questions, we conduct an empirical study of performance divergence in rule-based C-to-Rust translation using C2RUST [8], a transpiler widely adopted in research [10],

[30] and industry [20]. Its deterministic translation enables controlled paired C–Rust performance comparison. We construct a benchmark of 20 real-world C projects and their C2RUST translations, using eight projects as the Study Dataset for empirical analysis and reserving the remaining twelve for evaluation. We measure performance at the granularity of operations, each being a complete program task with checkable output that may span multiple API calls, such as compression or decompression in BZIP2. Across 19 operations in the Study Dataset, the translated Rust incurs more than 3.0% runtime overhead over C on 12, eight of which exceed 25.0% with a maximum of 62.2%. Execution-cost decomposition reveals three recurring profiles: additional dynamic instructions, higher cycles per instruction, or both. We trace these differences through optimized IR, compiler optimization remarks, and translated Rust source, identifying nine recurring performance issues. These issues span residual runtime work, missed compiler transformations, and recurring source-level patterns, each with a corresponding optimization direction.

Building on these findings, we present PERFR, a rule-guided framework for recovering performance lost during C-to-Rust migration. PERFR operationalizes each identified performance issue as an optimization guidance that pairs its Observed Pattern with the corresponding Optimization Direction. Given a C project, PERFR first obtains its unmodified C2RUST translation (denoted RAWRUST), constructs operation-level functional and performance workloads, and performs pre-optimization normalization. PERFR then localizes rule-specific issues in hot functions using optimized IR, compiler remarks, and Rust source. For each pattern group, the LLM evaluates rewrite preconditions against project context and synthesizes a candidate rewrite using the applicable optimization directions. Each candidate is accepted only if it preserves functionality and yields a net runtime improvement across the synthesized workloads.

We evaluate PERFR on twelve held-out projects against RAWRUST and CODEX, a general-purpose coding agent, using C as the runtime reference. PERFR preserves C outputs on all 41 operations and reduces measured runtime relative to RAWRUST on 40. After optimization, 18 operations run faster than C, including 10 by more than 3%. On MINIZ checksum computation, for example, overhead changes from +16.7% for RAWRUST to -66.0% for PERFR. Compared with CODEX, which produces non-equivalent outputs on four operations, PERFR achieves lower measured runtime on 31 of the 37 operations for which both preserve C outputs. Finally, starting from the same refined baseline, rule-guided optimization achieves lower runtime than unguided optimization on 34 of 41 operations. This paper makes the following contributions:

• Empirical characterization. We construct a 20-project benchmark and characterize performance divergence through runtime analysis, identifying nine recurring performance issues with corresponding optimization directions.

• Rule-guided performance optimization. We develop PERFR, which turns the identified performance issues into reusable optimization rules and applies them through hotspot-guided detection, precondition-aware LLM rewriting, and functional and performance validation.

• Cross-project evaluation. We evaluate PERFR on twelve projects disjoint from rule derivation, compare its performance with C, RAWRUST, and CODEX, and examine rule applicability and the effectiveness of the rule-guided mechanism through an unguided ablation.

References (55)