Skip to content

Commit e65098b

Browse files
committed
Rollup merge of rust-lang#50407 - nnethercote:inline-BytePos, r=michaelwoerister
Always inline simple BytePos and CharPos methods. Because they are (a) trivial, and (b) super hot. This change speeds up most rustc-perf benchmarks, the best by 5%. Full measurements: ``` coercions-check avg: -3.0% min: -5.4% max: -1.3% helloworld-check avg: -3.9% min: -4.1% max: -3.6% unify-linearly-check avg: -3.1% min: -3.7% max: -2.5% deeply-nested-check avg: -2.6% min: -3.6% max: -2.1% coercions-opt avg: -2.1% min: -3.6% max: -1.3% coercions avg: -2.0% min: -3.5% max: -1.0% issue-46449-check avg: -2.8% min: -3.1% max: -2.6% parser-check avg: -2.6% min: -3.1% max: -2.0% deeply-nested-opt avg: -1.5% min: -3.0% max: -0.8% deeply-nested avg: -1.8% min: -2.9% max: -1.1% issue-46449 avg: -1.4% min: -2.7% max: -1.1% issue-46449-opt avg: -1.0% min: -2.7% max: -0.5% regression-31157-check avg: -1.7% min: -2.3% max: -1.1% tuple-stress-opt avg: -1.0% min: -2.2% max: -0.5% tokio-webpush-simple-check avg: -1.6% min: -2.1% max: -1.2% tuple-stress-check avg: -1.2% min: -2.1% max: -0.8% unused-warnings-check avg: -1.6% min: -2.0% max: -1.4% encoding-check avg: -1.4% min: -1.8% max: -1.0% tuple-stress avg: -1.0% min: -1.7% max: -0.6% encoding-opt avg: -0.9% min: -1.6% max: -0.3% unused-warnings avg: -1.3% min: -1.6% max: -1.2% unused-warnings-opt avg: -1.3% min: -1.5% max: -1.2% encoding avg: -1.0% min: -1.5% max: -0.4% html5ever-opt avg: -0.7% min: -1.5% max: -0.3% futures avg: -1.0% min: -1.5% max: -0.5% futures-check avg: -1.0% min: -1.5% max: -0.5% futures-opt avg: -0.8% min: -1.4% max: -0.3% regression-31157-opt avg: -0.5% min: -1.4% max: -0.0% unify-linearly-opt avg: -1.2% min: -1.4% max: -1.0% parser-opt avg: -1.2% min: -1.4% max: -1.0% helloworld avg: -1.3% min: -1.4% max: -1.3% helloworld-opt avg: -1.3% min: -1.3% max: -1.3% parser avg: -1.2% min: -1.3% max: -1.0% regex-check avg: -1.1% min: -1.3% max: -0.7% unify-linearly avg: -1.1% min: -1.3% max: -1.0% syn-check avg: -0.8% min: -1.3% max: -0.3% piston-image-check avg: -0.7% min: -1.2% max: -0.4% regex-opt avg: -0.5% min: -1.2% max: -0.0% syn avg: -0.6% min: -1.2% max: -0.3% hyper avg: -0.8% min: -1.2% max: -0.4% syn-opt avg: -0.5% min: -1.2% max: -0.1% regex avg: -0.7% min: -1.2% max: -0.3% regression-31157 avg: -0.7% min: -1.2% max: -0.3% clap-rs-check avg: -0.6% min: -1.1% max: -0.2% hyper-check avg: -0.8% min: -1.1% max: -0.5% piston-image-opt avg: -0.4% min: -1.1% max: -0.0% hyper-opt avg: -0.6% min: -1.0% max: 0.0% inflate avg: -0.4% min: -1.0% max: -0.2% html5ever avg: -0.5% min: -1.0% max: -0.2% inflate-opt avg: -0.3% min: -1.0% max: 0.3% deep-vector-check avg: -0.6% min: -1.0% max: -0.3% style-servo-check avg: -0.7% min: -1.0% max: -0.5% tokio-webpush-simple-opt avg: -0.3% min: -0.9% max: 0.0% inflate-check avg: -0.3% min: -0.9% max: -0.1% piston-image avg: -0.4% min: -0.8% max: -0.2% deep-vector avg: -0.4% min: -0.8% max: -0.1% clap-rs avg: -0.4% min: -0.7% max: -0.2% deep-vector-opt avg: -0.2% min: -0.7% max: 0.2% style-servo avg: -0.3% min: -0.7% max: 0.1% crates.io avg: -0.4% min: -0.6% max: -0.2% crates.io-opt avg: -0.3% min: -0.6% max: -0.1% tokio-webpush-simple avg: -0.4% min: -0.6% max: -0.3% crates.io-check avg: -0.4% min: -0.6% max: -0.3% html5ever-check avg: -0.4% min: -0.6% max: -0.2% serde avg: -0.1% min: -0.6% max: 0.2% serde-check avg: -0.1% min: -0.5% max: 0.4% serde-opt avg: -0.2% min: -0.5% max: -0.1% style-servo-opt avg: -0.2% min: -0.4% max: -0.0% clap-rs-opt avg: -0.1% min: -0.3% max: 0.0%
2 parents cd6fa5f + e740b97 commit e65098b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libsyntax_pos/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,13 +1150,17 @@ pub struct CharPos(pub usize);
11501150
// have been unsuccessful
11511151

11521152
impl Pos for BytePos {
1153+
#[inline(always)]
11531154
fn from_usize(n: usize) -> BytePos { BytePos(n as u32) }
1155+
1156+
#[inline(always)]
11541157
fn to_usize(&self) -> usize { let BytePos(n) = *self; n as usize }
11551158
}
11561159

11571160
impl Add for BytePos {
11581161
type Output = BytePos;
11591162

1163+
#[inline(always)]
11601164
fn add(self, rhs: BytePos) -> BytePos {
11611165
BytePos((self.to_usize() + rhs.to_usize()) as u32)
11621166
}
@@ -1165,6 +1169,7 @@ impl Add for BytePos {
11651169
impl Sub for BytePos {
11661170
type Output = BytePos;
11671171

1172+
#[inline(always)]
11681173
fn sub(self, rhs: BytePos) -> BytePos {
11691174
BytePos((self.to_usize() - rhs.to_usize()) as u32)
11701175
}
@@ -1183,13 +1188,17 @@ impl Decodable for BytePos {
11831188
}
11841189

11851190
impl Pos for CharPos {
1191+
#[inline(always)]
11861192
fn from_usize(n: usize) -> CharPos { CharPos(n) }
1193+
1194+
#[inline(always)]
11871195
fn to_usize(&self) -> usize { let CharPos(n) = *self; n }
11881196
}
11891197

11901198
impl Add for CharPos {
11911199
type Output = CharPos;
11921200

1201+
#[inline(always)]
11931202
fn add(self, rhs: CharPos) -> CharPos {
11941203
CharPos(self.to_usize() + rhs.to_usize())
11951204
}
@@ -1198,6 +1207,7 @@ impl Add for CharPos {
11981207
impl Sub for CharPos {
11991208
type Output = CharPos;
12001209

1210+
#[inline(always)]
12011211
fn sub(self, rhs: CharPos) -> CharPos {
12021212
CharPos(self.to_usize() - rhs.to_usize())
12031213
}

0 commit comments

Comments
 (0)