diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-05-30 15:59:45 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-06-01 10:36:39 +1000 |
| commit | 0b81d7cdc653f540e9fa219820928184e0273f5f (patch) | |
| tree | e76c89dfae58c1794785b639cd5553627918cf77 /compiler/rustc_query_impl/src | |
| parent | bef2b7cd1c7bcb3393f10d5752fcf9ee3026bce8 (diff) | |
| download | rust-0b81d7cdc653f540e9fa219820928184e0273f5f.tar.gz rust-0b81d7cdc653f540e9fa219820928184e0273f5f.zip | |
Lazify `SourceFile::lines`.
`SourceFile::lines` is a big part of metadata. It's stored in a compressed form (a difference list) to save disk space. Decoding it is a big fraction of compile time for very small crates/programs. This commit introduces a new type `SourceFileLines` which has a `Lines` form and a `Diffs` form. The latter is used when the metadata is first read, and it is only decoded into the `Lines` form when line data is actually needed. This avoids the decoding cost for many files, especially in `std`. It's a performance win of up to 15% for tiny crates/programs where metadata decoding is a high part of compilation costs. A `Lock` is needed because the methods that access lines data (which can trigger decoding) take `&self` rather than `&mut self`. To allow for this, `SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather than returning the lines slice.
Diffstat (limited to 'compiler/rustc_query_impl/src')
| -rw-r--r-- | compiler/rustc_query_impl/src/on_disk_cache.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index 8e4b3269402..5a915933dc5 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -713,7 +713,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Span { let len = BytePos::decode(decoder); let file_lo = decoder.file_index_to_file(file_lo_index); - let lo = file_lo.lines[line_lo - 1] + col_lo; + let lo = file_lo.lines(|lines| lines[line_lo - 1] + col_lo); let hi = lo + len; Span::new(lo, hi, ctxt, parent) |
