@@ -212,25 +212,31 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
212
212
213
213
/// Identifies whether a predicate obligation needs processing.
214
214
///
215
- /// This is always inlined, despite its size, because it has a single
216
- /// callsite and it is called *very* frequently.
215
+ /// This is always inlined because it has a single callsite and it is
216
+ /// called *very* frequently. Be careful modifying this code! Several
217
+ /// compile-time benchmarks are very sensitive to even small changes.
217
218
#[ inline( always) ]
218
219
fn needs_process_obligation ( & self , pending_obligation : & Self :: Obligation ) -> bool {
219
- // If we were stalled on some unresolved variables, first check whether
220
- // any of them have been resolved; if not, don't bother doing more work
221
- // yet.
222
- match pending_obligation. stalled_on . len ( ) {
223
- // Match arms are in order of frequency, which matters because this
224
- // code is so hot. 1 and 0 dominate; 2+ is fairly rare.
225
- 1 => {
226
- let infer_var = pending_obligation. stalled_on [ 0 ] ;
227
- self . selcx . infcx . inlined_ty_or_const_infer_var_changed ( infer_var)
228
- }
229
- 0 => {
230
- // In this case we haven't changed, but wish to make a change.
231
- true
232
- }
233
- _ => pending_obligation. stalled_on . iter ( ) . any ( |& infer_var| {
220
+ let stalled_on = & pending_obligation. stalled_on ;
221
+ match stalled_on. len ( ) {
222
+ // This case is the hottest most of the time, being hit up to 99%
223
+ // of the time. `keccak` and `cranelift-codegen-0.82.1` are
224
+ // benchmarks that particularly stress this path.
225
+ 1 => self . selcx . infcx . inlined_ty_or_const_infer_var_changed ( stalled_on[ 0 ] ) ,
226
+
227
+ // In this case we haven't changed, but wish to make a change. Note
228
+ // that this is a special case, and is not equivalent to the `_`
229
+ // case below, which would return `false` for an empty `stalled_on`
230
+ // vector.
231
+ //
232
+ // This case is usually hit only 1% of the time or less, though it
233
+ // reaches 20% in `wasmparser-0.101.0`.
234
+ 0 => true ,
235
+
236
+ // This case is usually hit only 1% of the time or less, though it
237
+ // reaches 95% in `mime-0.3.16`, 64% in `wast-54.0.0`, and 12% in
238
+ // `inflate-0.4.5`.
239
+ _ => stalled_on. iter ( ) . any ( |& infer_var| {
234
240
self . selcx . infcx . uninlined_ty_or_const_infer_var_changed ( infer_var)
235
241
} ) ,
236
242
}
0 commit comments