-
Notifications
You must be signed in to change notification settings - Fork 269
Expose Event::HardBreak style #1034
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
Being that this information is already parsed into ItemBody and the user might want to behave differently depending on the style (either backslash or double spaced) of the hardbreak I think it's the best option to expose it as a new enum. This issue came up in Clippy, we has to do very weird things to get the hardbreak style, and results in performance issues. Sorry if this is controversial enough to need an issue.
ollpu
left a comment
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.
Thanks! I think this makes sense, and is in line with some other enums we already expose. Check fmt!
Those other enums tend to be named ..Kind, so maybe this should be the same for the sake of uniformity, HardBreakKind?
Strictly speaking, the double-space style/kind is "two or more spaces", so I wonder if there's a more accurate name. Spaces?
By the way, do you have a pointer to the poorly performing post-hoc implementation in Clippy? I'm curious because I imagine it to be a relatively simple check if you know the event spans (with OffsetIter)
Also, format
623d18e to
cc77981
Compare
|
This line A calls |
|
Oh I didn't see the failling CI :/ GitHub seems to be funky with the CI interface in this PR. |
Turns out that `doc_markdown` uses a non-cheap rustdoc function to convert from markdown ranges into source spans. And it was using it a lot (about once every 18 lines of documentation on `tokio`, which ends up being about 1800 times). This ended up being about 18% of the total Clippy runtime as discovered by lintcheck --perf in docs-heavy crates. This PR optimizes one of the cases in which Clippy calls the function, and a future PR once pulldown-cmark/pulldown-cmark#1034 is merged will be open. Note that not all crates were affected by this crate equally, those with more docs are affected far more than those light ones.
I see, but I suppose you don't have to go through that machinery to get the snippet and perform the check? - if let Some(span) = fragments.span(cx, range.clone())
- && !span.from_expansion()
- && let Some(snippet) = snippet_opt(cx, span)
- && !snippet.trim().starts_with('\\')
- && event == HardBreak {
- collected_breaks.push(span);
- }
+ if event == HardBreak
+ && !doc[range.clone()].trim().starts_with('\\')
+ && let Some(span) = fragments.span(cx, range.clone())
+ && !span.from_expansion() {
+ collected_breaks.push(span);
+ }(Edit: Also do the HardBreak check first to avoid string slicing, since softs are much more common) CI now failing from missing |
|
Honestly, I'm not sure how to proceed 😅 This PR is then a little bit redundant in our specific case. If the project would still appreciate it, I can do the necessary fixes for CI (which is proving tricky, I'll manually check If you think that it does not add any value, I have no problems closing it and using the patch you provided (with the appropriate authoring information for the commit) |
|
I'm not sure either. Clearly there is a use for distinguishing the kinds of hard break, but it can be recovered fairly easily with offsets. The downside to this change is it makes it more cumbersome to match on From a princpled perspective, if we add this, then in some sense we're also welcoming other AST enrichments like:
Also related to the discussion in #892 Opinions? @Martin1887 @notriddle Either way, you're welcome to incorporate my patch in Clippy :) |
|
I totally agree with your conclusions, we have to think about maintaining the current code or exposing more details, with a more cumbersome interface and breaking changes. Thanks! |
|
In that case, I'll close this PR. In case that in a distant future this feature is more needed in the project feel free to implement it without attribution hassle (it's a 20 line change) Thanks for the feedback and the reviews, and have a good week! |
) Turns out that `doc_markdown` uses a non-cheap rustdoc function to convert from markdown ranges into source spans. And it was using it a lot (about once every 17 lines of documentation on `tokio`, which ends up being about 2000 times). This ended up being about 18% of the total Clippy runtime as discovered by lintcheck --perf in docs-heavy crates. This PR optimizes one of the cases in which Clippy calls the function, and a future PR once pulldown-cmark/pulldown-cmark#1034 is merged will be opened. This PR lands the use of the function into the single-digit zone. Note that not all crates were affected by this crate equally, those with more docs are affected far more than those light ones. changelog:[`clippy::doc_markdown`] has been optimized by 50%
Being that this information is already parsed into ItemBody and the user might want to behave differently depending on the style (either backslash or double spaced) of the hardbreak
I think it's the best option to expose it as a new enum.
This issue came up in Clippy, we has to do very weird things to get the hardbreak style, and results in performance issues. Sorry if this is controversial enough to need an issue.