From a86544b799b0fe81e2e2a734a2b49d16faad4f3d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 22 May 2018 16:51:28 +1000 Subject: [PATCH] Right-size the `VecDeque` in `coerce_unsized`. The default capacity of a VecDeque is 8, which is excessive here. In a "base incremental" check build of rustc-perf's tuple-stress benchmark, this decreases total heap allocation by 26%. I couldn't see a clear speedup, but it can't hurt. --- src/librustc_typeck/check/coercion.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 324af7b62704d..1905ffef8db18 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -537,8 +537,9 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> { let mut selcx = traits::SelectionContext::new(self); - // Use a FIFO queue for this custom fulfillment procedure. - let mut queue = VecDeque::new(); + // Use a FIFO queue for this custom fulfillment procedure. (The maximum + // length is almost always 1.) + let mut queue = VecDeque::with_capacity(1); // Create an obligation for `Source: CoerceUnsized`. let cause = ObligationCause::misc(self.cause.span, self.body_id);