]> git.lizzy.rs Git - rust.git/commit
Avoid many `cmt` allocations.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 2 May 2018 00:28:37 +0000 (10:28 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Thu, 3 May 2018 12:14:35 +0000 (22:14 +1000)
commit7cf142f78b82b0b2ae08b52ccb6a6e15c0270c38
tree8c2bde3dcd85a2b9bbb49d281966cb52c47cb5c6
parentf76f6fbdea497c3cb536e33387f405cc74b99b76
Avoid many `cmt` allocations.

`cmt` is a ref-counted wrapper around `cmt_` The use of refcounting
keeps `cmt` handling simple, but a lot of `cmt` instances are very
short-lived, and heap-allocating the short-lived ones takes up time.

This patch changes things in the following ways.

- Most of the functions that produced `cmt` instances now produce `cmt_`
  instances. The `Rc::new` calls that occurred within those functions
  now occur at their call sites (but only when necessary, which isn't
  that often).

- Many of the functions that took `cmt` arguments now take `&cmt_`
  arguments. This includes all the methods in the `Delegate` trait.

As a result, the vast majority of the heap allocations are avoided. In
an extreme case, the number of calls to malloc in tuple-stress drops
from 9.9M to 7.9M, a drop of 20%. And the compile times for many runs of
coercions, deep-vector, and tuple-stress drop by 1--2%.
12 files changed:
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/mem_categorization.rs
src/librustc_borrowck/borrowck/check_loans.rs
src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
src/librustc_borrowck/borrowck/gather_loans/lifetime.rs
src/librustc_borrowck/borrowck/gather_loans/mod.rs
src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
src/librustc_borrowck/borrowck/mod.rs
src/librustc_mir/hair/pattern/check_match.rs
src/librustc_passes/rvalue_promotion.rs
src/librustc_typeck/check/regionck.rs
src/librustc_typeck/check/upvar.rs