Slower code generation with target-cpu=x86-64-v3 and target-cpu=native (i7-12700K, rustc 1.100.1)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- rust
- 領域
- compilers, performance
調査の方向性
Use the linked reproducer as the entry point, focusing on distance in main and the default, x86-64-v3, and native release builds. Compare generated instructions with perf stat and inspect rustc/LLVM code generation for the affected target features. Done means identifying why the specialized targets use more instructions and either fixing the regression or isolating it to the relevant compiler component, with the reproducer demonstrating the result.
索引モデルが issue の本文から書いたものです。
説明
I tried this code:
use std::{hint::black_box, time::Instant};
fn distance(a: &[f64], b: &[f64]) -> f64 {
let b = &b[..a.len()];
let mut total = 0.0;
for i in 0..a.len() {
let diff = a[i] - b[i];
total += diff * diff;
}
total.sqrt()
}
fn main() {
let vec1: Vec<f64> = (0..20).map(|i| i as f64).collect();
let vec2: Vec<f64> = (1..21).map(|i| i as f64).collect();
let start = Instant::now();
for _ in 0..10_000_000 {
black_box(distance(black_box(&vec1), black_box(&vec2)));
}
println!("Elapsed: {}µs", start.elapsed().as_micros());
}
I expected changing the target-cpu to x86-64-v3 or native to be maybe faster, but at least no slower.
Instead, this happened:
target-cpu default
Elapsed: 80764µs
Benchmark 1: ./target/release/slow-target-cpu
Time (mean ± σ): 63.2 ms ± 0.4 ms [User: 62.2 ms, System: 0.8 ms]
Range (min … max): 62.6 ms … 63.9 ms 47 runs
target-cpu=x86-64-v3
Elapsed: 82101µs
Benchmark 1: ./target/release/slow-target-cpu
Time (mean ± σ): 74.5 ms ± 0.3 ms [User: 73.7 ms, System: 0.5 ms]
Range (min … max): 73.9 ms … 75.4 ms 40 runs
target-cpu=native
Elapsed: 80808µs
Benchmark 1: ./target/release/slow-target-cpu
Time (mean ± σ): 74.5 ms ± 0.4 ms [User: 73.6 ms, System: 0.6 ms]
Range (min … max): 73.9 ms … 75.4 ms 40 runs
Full reproducer: https://github.com/itamarst/slow-target-cpu/
One thing I noticed is that the custom target-cpus resulted in more CPU instructions being used, per perf stat:
# Default compilation:
110,592,237 cpu_core/branches/ # 1774.4 M/sec branch_frequency
222,261,251 cpu_core/cpu-cycles/ # 3.6 GHz cycles_frequency
1,233,238,814 cpu_core/instructions/ # 5.5 instructions insn_per_cycle
# -C target-cpu=native compilation:
120,602,162 cpu_core/branches/ # 1609.7 M/sec branch_frequency
266,475,431 cpu_core/cpu-cycles/ # 3.6 GHz cycles_frequency
1,303,335,985 cpu_core/instructions/ # 4.9 instructions insn_per_cycle
Meta
rustc --version --verbose:
rustc 1.100.1 (20ddd0171 2026-11-25)
binary: rustc
commit-hash: 20ddd01716a87c0fcf06ae4752d85a4abc15bcdf
commit-date: 2026-11-25
host: x86_64-unknown-linux-gnu
release: 1.100.1
LLVM version: 23.1.5
- 主要言語
- Rust
- スター
- 123k
- フォーク
- 16.6k
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 532
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/rust のほかの issue
-
C-bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
rust-lang/rust#166722 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
A-attributes relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-lang
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
A-run-make C-bug T-bootstrap
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
Tracking issue for release notes of #161531: Remove `T: Send + Sync` bound from `Arc::downcast`オープンrelnotes relnotes-tracking-issue T-libs
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
A-str A-Unicode relnotes relnotes-tracking-issue T-libs
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
bug core-lang
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Windows microphone listing treats words in a device name as DirectShow labels対応中かも @Sujal-chaudhary が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
clipy-recorder/clipy#447 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
nightly-cleanup
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
max-sixty/worktrunk#4939 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信