-
Notifications
You must be signed in to change notification settings - Fork 14k
Simplify code to generate line numbers in highlight #148171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I don't think it'll impact performance but just in case: @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.
Simplify code to generate line numbers in highlight
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (b384be5): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary 4.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 473.665s -> 475.551s (0.40%) |
|
It's actually faster. I'm surprised. Oh well, good surprises are welcome I guess. 😆 |
|
I'm not surprised at all, it's removing an intermediate allocation, I would expect that to improve performance slightly. |
src/librustdoc/html/highlight.rs
Outdated
| /// Used for non-scraped code examples, ie source code pages and code examples in documentation. | ||
| Normal(u32), | ||
| /// Code examples without line numbers. | ||
| #[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- as far as I can tell, code examples in documentation don't have line numbers (and if they did, we wouldn't want them to have line number anchors, otherwise multiple examples would end up with conflicting IDs)
- the
dead_codeseems unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'm guessing it's because the data of the
Emptyvariant (i.e. theu32) is never read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
| if let Some(backline) = token_handler.handle_backline() { | ||
| token_handler.push_token_without_backline_check( | ||
| None, | ||
| Cow::Owned(backline.to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that we're using Cow::Owned here didn't sit right to me, so I did some digging and found out push_token_without_backline_check has overly restrictive lifetimes. It should use text: Cow<'_, str>, not text: Cow<'a, str>.
Actually, I think it could even be just text: &str, since it doesn't look like the code ever takes advantage of the Owned case and instead just uses it as impl Display, but that would require more refactoring than just changing a lifetime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backline is a LineNumber, so we need to convert it to something compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, I think impl Display would also work? not sure the monomorphization would be worth it, could maybe experiment in a follow-up PR.
Regardless, the lifetime still is overly restrictive, and it's hard to see that as anything but a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, might be worth trying in a follow-up.
src/librustdoc/html/highlight.rs
Outdated
| /// used to generate links. | ||
| href_context: Option<HrefContext<'a, 'tcx>>, | ||
| write_line_number: fn(u32) -> String, | ||
| write_line_number: fn(u32) -> LineNumber, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The enum is a nice touch, but maybe we can go one step further and make it into a data-less, C-like enum? So line_number: LineNumber or something, instead of holding an fn pointer.
Fn pointers probably aren't great for perf (I think they can't be inlined? unless the compiler/LLVM are smart enough to make it into a sort-of enum?)
And also, might make code slightly nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Gonna implement that.
src/librustdoc/html/highlight.rs
Outdated
| /// Used for non-scraped code examples, ie source code pages and code examples in documentation. | ||
| Normal(u32), | ||
| /// Code examples without line numbers. | ||
| #[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'm guessing it's because the data of the
Emptyvariant (i.e. theu32) is never read?
db4815c to
04a10f7
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Simplified it even further thanks to both your feedback! Let's check perf now. =D @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.
Simplify code to generate line numbers in highlight
|
In favor of merging this and refactoring |
src/librustdoc/html/highlight.rs
Outdated
| // https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag#data-nosnippet-attr | ||
| // Do not show "1 2 3 4 5 ..." in web search results. | ||
| format!("<a href=#{line} id={line} data-nosnippet>{line}</a>") | ||
| /// Represents line numbers to be generated as HTML. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| /// Represents line numbers to be generated as HTML. | |
| /// Represents the type of line number to be generated as HTML. |
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, adding it. :)
src/librustdoc/html/highlight.rs
Outdated
| /// used to generate links. | ||
| href_context: Option<HrefContext<'a, 'tcx>>, | ||
| write_line_number: fn(u32) -> String, | ||
| write_line_number: LineNumberKind, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| write_line_number: LineNumberKind, | |
| line_number_kind: LineNumberKind, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
Apart from two super-small nits, I think this should be merged :) |
|
Let's wait for perf first then. :) |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (d3e852c): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -2.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 5.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 474.501s -> 475.417s (0.19%) |
|
Nice! Thanks to both of you. :) @bors r=yotamofek,lolbinarycat rollup |
…ht, r=yotamofek,lolbinarycat Simplify code to generate line numbers in highlight Follow-up of rust-lang#146992. cc `@yotamofek` r? `@lolbinarycat`
…ht, r=yotamofek,lolbinarycat Simplify code to generate line numbers in highlight Follow-up of rust-lang#146992. cc ``@yotamofek`` r? ``@lolbinarycat``
…ht, r=yotamofek,lolbinarycat Simplify code to generate line numbers in highlight Follow-up of rust-lang#146992. cc ```@yotamofek``` r? ```@lolbinarycat```
…ht, r=yotamofek,lolbinarycat Simplify code to generate line numbers in highlight Follow-up of rust-lang#146992. cc ````@yotamofek```` r? ````@lolbinarycat````
Rollup of 10 pull requests Successful merges: - #135602 (Tweak output of missing lifetime on associated type) - #139751 (Implement pin-project in pattern matching for `&pin mut|const T`) - #142682 (Update bundled musl to 1.2.5) - #148171 (Simplify code to generate line numbers in highlight) - #148263 (Unpin `libc` and `rustix` in `compiler` and `rustbook`) - #148301 ([rustdoc search] Include extern crates when filtering on `import`) - #148330 (Don't require dlltool with the dummy backend on MinGW) - #148338 (cleanup: upstream dropped amx-transpose functionality) - #148340 (Clippy subtree update) - #148343 (`nonpoison::Condvar` should take `MutexGuard` by reference) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 10 pull requests Successful merges: - #135602 (Tweak output of missing lifetime on associated type) - #139751 (Implement pin-project in pattern matching for `&pin mut|const T`) - #142682 (Update bundled musl to 1.2.5) - #148171 (Simplify code to generate line numbers in highlight) - #148263 (Unpin `libc` and `rustix` in `compiler` and `rustbook`) - #148301 ([rustdoc search] Include extern crates when filtering on `import`) - #148330 (Don't require dlltool with the dummy backend on MinGW) - #148338 (cleanup: upstream dropped amx-transpose functionality) - #148340 (Clippy subtree update) - #148343 (`nonpoison::Condvar` should take `MutexGuard` by reference) r? `@ghost` `@rustbot` modify labels: rollup
Follow-up of #146992.
cc @yotamofek
r? @lolbinarycat