diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-09-14 21:28:55 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-09-14 21:28:55 -0700 |
| commit | a7817dd52cb3f830504cdf702f726a0c0b7685dd (patch) | |
| tree | 55abbdf81dbcf984b493e747e6393027c0fd59ff /src/librustc_data_structures | |
| parent | 2d288a5ae5e2e72b1c40611db80f94bbec75639b (diff) | |
| download | rust-a7817dd52cb3f830504cdf702f726a0c0b7685dd.tar.gz rust-a7817dd52cb3f830504cdf702f726a0c0b7685dd.zip | |
rustc: Preallocate when building the dep graph
This commit alters the `query` function in the dep graph module to preallocate memory using `with_capacity` instead of relying on automatic growth. Discovered in #44576 it was found that for the syntex_syntax clean incremental benchmark the peak memory usage was found when the dep graph was being saved, particularly the `DepGraphQuery` data structure itself. PRs like #44142 which add more queries end up just making this much larger! I didn't see an immediately obvious way to reduce the size of the `DepGraphQuery` object, but it turns out that `with_capacity` helps quite a bit! Locally 831 MB was used [before] this commit, and 770 MB is in use at the peak of the compiler [after] this commit. That's a nice 7.5% improvement! This won't quite make up for the losses in #44142 but I figured it's a good start. [before]: https://gist.github.com/alexcrichton/2d2b9c7a65503761925c5a0bcfeb0d1e [before]: https://gist.github.com/alexcrichton/6da51f2a6184bfb81694cc44f06deb5b
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/graph/mod.rs | 7 | ||||
| -rw-r--r-- | src/librustc_data_structures/snapshot_vec.rs | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/librustc_data_structures/graph/mod.rs b/src/librustc_data_structures/graph/mod.rs index a5f83ce05f5..474622f3669 100644 --- a/src/librustc_data_structures/graph/mod.rs +++ b/src/librustc_data_structures/graph/mod.rs @@ -114,6 +114,13 @@ impl<N: Debug, E: Debug> Graph<N, E> { } } + pub fn with_capacity(nodes: usize, edges: usize) -> Graph<N, E> { + Graph { + nodes: SnapshotVec::with_capacity(nodes), + edges: SnapshotVec::with_capacity(edges), + } + } + // # Simple accessors #[inline] diff --git a/src/librustc_data_structures/snapshot_vec.rs b/src/librustc_data_structures/snapshot_vec.rs index dac074ab91e..2da91918288 100644 --- a/src/librustc_data_structures/snapshot_vec.rs +++ b/src/librustc_data_structures/snapshot_vec.rs @@ -66,6 +66,13 @@ impl<D: SnapshotVecDelegate> SnapshotVec<D> { } } + pub fn with_capacity(n: usize) -> SnapshotVec<D> { + SnapshotVec { + values: Vec::with_capacity(n), + undo_log: Vec::new(), + } + } + fn in_snapshot(&self) -> bool { !self.undo_log.is_empty() } |
