]> git.lizzy.rs Git - rust.git/commit
Avoid regenerating the `Vec<PathBuf>` in `FileSearch::search()`.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 20 Nov 2018 00:06:45 +0000 (11:06 +1100)
committerNicholas Nethercote <nnethercote@mozilla.com>
Tue, 11 Dec 2018 23:36:15 +0000 (10:36 +1100)
commit2bfe32cc9301d404c98d896efbabe8f04361d5bf
tree667bba60d155cb2d2eca50df9e66165f34be7735
parentf13006182c9df451e7703307467fc1717239cf6e
Avoid regenerating the `Vec<PathBuf>` in `FileSearch::search()`.

`FileSearch::search()` traverses one or more directories. For each
directory it generates a `Vec<PathBuf>` containing one element per file
in that directory.

In some benchmarks this occurs enough that the allocations done for the
`PathBuf`s are significant, and in practice a small number of
directories are being traversed over and over again. For example, when
compiling the `tokio-webpush-simple` benchmark, two directories are
traversed 58 times each. Each of these directories have more than 100
files.

This commit changes things so that all the `Vec<PathBuf>`s that will be
needed by a `Session` are precomputed when that `Session` is created;
they are stored in `SearchPath`. `FileSearch` gets a reference to the
necessary `SearchPath`s. This reduces instruction counts on several
benchmarks by 1--5%.

The commit also removes the barely-used `visited_dirs` hash in
`for_each_lib_searchPath`. It only detects if `tlib_path` is the same as
one of the previously seen paths, which is unlikely.
src/librustc/session/filesearch.rs
src/librustc/session/mod.rs
src/librustc/session/search_paths.rs