Repository navigation
Conversation
It is unused since 3ccabc6
We are computing the display column of a position by decoding every char from the start of its line for the location of every possible panic, so a file with very long lines takes quadratic time. (This is the case for a generated file that can get very long lines) For most code (ascii without tabs) the column is the byte index. So optimize the fast path. On a ~5 MB generated single line file, the build goes from 161s to 15s
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| } | ||
|
|
||
| let (lines, multibyte_chars) = analyze_source_file::analyze_source_file(&src); | ||
| let may_contain_tabs = src.contains('\t'); |
There was a problem hiding this comment.
I considered trying to do this in analyze_source_file::analyze_source_file doing that at the same time as breaking lines and detecting non-ascii, but that is more involved and i hope contains is optimized enough already.
|
I assume you want to measure this? @bors try @rust-timer queue Also note that this likely interacts with LLM policy: https://forge.rust-lang.org/policies/llm-usage.html |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Optimize display column calculation
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (b0e2506): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 0.4%, secondary 1.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -0.5%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 487.289s -> 487.926s (0.13%) |
They don't belong here and so we skip trying to find new lines and non-ascii char. The refactor also mean that `include_str!` will be added after utf8 parsing. as a result, we now see the contents for the note. I believe this is the intended behavior of `utf8_error`.
|
The regression hapenned in |
|
Could I request another benchmark run? |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Optimize display column calculation
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (a0c8c8c): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -0.1%, secondary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -0.4%, secondary -0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 486.908s -> 488.286s (0.28%) |
| /// Locations of multi-byte characters in the source code. | ||
| pub multibyte_chars: Vec<MultiByteChar>, | ||
| /// Whether the source may contain a tab. Always true when the source text isn't available. | ||
| may_contain_tabs: bool, |
There was a problem hiding this comment.
This is just incorrect because tabs are not the only issue, also non-ASCII characters as well. In particular, a useful test case is to add /* 悪 */ to the middle of a line, where the middle character is:
- one char
- two columns
- three bytes
Instead of may_contain_tabs, this should be columns_are_always_byte_offsets, which is technically an inverse but more reasonable to understand.
There was a problem hiding this comment.
So, rereading the code, I do see that you use the multi-byte character positions, but at this point why not just rename them to multi-column chars and treat tabs as multi-column?
There was a problem hiding this comment.
Because non-ascii is already handled separately. And it is common (imho) that a file has either lots of tabs, or none.
But I can imagine files with a few non-ASCII in comments or strings in a couple of lines and it would be sad to pessimise this optimisation once you have a single non-ascii in your file.
|
r? clarfonthey in favor of prior review |
|
Side note: not formally on the compiler team but have been looking into this code and happy to review. Will probably pass onto someone on compiler again when I'm done with it. |
|
Yeah, I don't think I'll have time to look into this. r? compiler |
|
While the perf results for rustdoc are clearly green, those on the compiler show a clear regression. So it is not entirely clear to me whether the change is worth it.
While this is great, I don't think it's worth regressing normal benchmarks for such an outlier.
Thanks for honestly disclosing this! This is however in not allowed by the LLM policy. Specifically this change would require following the experiment rules which requires a pre-arranged reviewer. @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
☔ The latest upstream changes (presumably #166371) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |

View all comments
We are computing the display column of a position by decoding every
char from the start of its line for the location of every possible panic,
so a file with very long lines takes quadratic time.
(This is the case for a generated file that can get very long lines)
For most code (ascii without tabs) the column is the byte index.
So optimize the fast path.
On a ~5 MB generated single line file, the build goes from 161s to 15s
LLM disclosure: an AI agent was used to diagnose the issue and first iteration, but the patch was then iterated and simplified by me.