Fix performance regression in debuginfo file_metadata.#70803
Fix performance regression in debuginfo file_metadata.#70803bors merged 1 commit intorust-lang:masterfrom
Conversation
Finding the `SourceFile` associated with a `FileName` called `get_source_file` on the `SourceMap`, which does a linear search through all files in the `SourceMap`. This resolves the issue by passing the SourceFile in from the caller (which already had it available).
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
r? @eddyb Should we do a perf run to see if this fully resolves the regression? It seemed to resolve it in a few benchmarks I ran locally. |
| debug!("file_metadata: file_name: {}, defining_crate: {}", file_name, defining_crate); | ||
| debug!("file_metadata: file_name: {}, defining_crate: {}", source_file.name, defining_crate); | ||
|
|
||
| let source_file = cx.sess().source_map().get_source_file(file_name); |
There was a problem hiding this comment.
Ahh, I missed this during review! This is indeed unnecessarily slow.
| pub fn file_metadata( | ||
| cx: &CodegenCx<'ll, '_>, | ||
| file_name: &FileName, | ||
| source_file: &SourceFile, |
There was a problem hiding this comment.
Heh, I think I did this (plus removing defining_crate and relying on the more accurate source_file.is_imported()) in one of my PRs that has been sitting around.
|
Let's land it and see the results there, to reduce the time @bors r+ rollup=never p=10 |
|
📌 Commit 4cdceda has been approved by |
|
☀️ Test successful - checks-azure |
|
@arlosi: This change fixes most of the regressions, thanks. But I notice that the "clap-rs-debug patched incremental: println" benchmark regression is only partly fixed. Any ideas what happened there? |
|
@nnethercote this PR has fixed the regression: https://perf.rust-lang.org/compare.html?start=9e55101bb681010c82c3c827305e2665fc8f2aa0&end=607b8582362be8e26df7acc12fa242359d7edf95&stat=instructions:u |
|
@mati865: is that the right perf link? Those perf results look like not much changed. |
|
@nnethercote it's difference starting right before original PR and after this fix proving there is no big preformance hit. |
|
I see now that this caused a large regression in memory usage @arlosi: was that expected? Any thoughts on how it could be improved? |
|
@nnethercote It appears that the change that caused the CPU regression, also caused an rss improvement. And that fixing the CPU regression removed the rss improvement. The original change that contained the CPU regression went in on 2020-04-03, and the fix went in on 2020-04-05. Looking at the graph for cargo-debug max-rss over that time period shows an improvement in memory usage, then a matching regression: Here's the run that introduced the CPU regression (and rss improvement): The key difference that caused the CPU regression was adding this line: |


Fixes performance regression caused by #69718.
Finding the
SourceFileassociated with aFileNamecalledget_source_fileon theSourceMap, which does a linear search through all files in theSourceMap.This resolves the issue by passing the
SourceFilein from the caller (which already had it available) instead of theFileNameFixes #70785.