-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Allow lazy HTML escaping #137274
Allow lazy HTML escaping #137274
Conversation
r? @notriddle rustbot has assigned @notriddle. Use |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…<try> Allow lazy HTML escaping Inspired by [this comment](rust-lang#136828 (comment)) by `@aDotInTheVoid` . Makes `Escape` and `EscapeBodyText` accept any `impl fmt::Display`, instead of a `&str`, which allows us to avoid a few interim `String` allocations. This opens up room for more lazifying, but I'll keep those for a separate PR. Unfortunately, I think there might be a hit to performance because of the double vtable-indirection caused by wrapping a `fmt::Formatter` in another one, but I think that I should be able to gain that perf back by doing more lazy printing (either the small things improvements I made in this PR, or in later ones) Probably better to review each commit individually.
This comment has been minimized.
This comment has been minimized.
c7f0154
to
1dd2f33
Compare
I've got an idea that seems simpler and better.
It already writes its escaped output into a Writer. Could rustdoc use that? |
Didn't know that crate, thanks for pointing that out! Alas, they don't support the "lazy" formatting I've implemented here, their API is used by calling So yeah, maybe we can replace our |
Their API is kinda opposite of ours: they have a function that allows writing a string into a writer, we have a wrapper for a string so that it can be escaped when written into a |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…<try> Allow lazy HTML escaping Inspired by [this comment](rust-lang#136828 (comment)) by `@aDotInTheVoid` . Makes `Escape` and `EscapeBodyText` accept any `impl fmt::Display`, instead of a `&str`, which allows us to avoid a few interim `String` allocations. This opens up room for more lazifying, but I'll keep those for a separate PR. Unfortunately, I think there might be a hit to performance because of the double vtable-indirection caused by wrapping a `fmt::Formatter` in another one, but I think that I should be able to gain that perf back by doing more lazy printing (either the small things improvements I made in this PR, or in later ones) Probably better to review each commit individually.
I see. That makes sense. (Anyway, you'd use escape_html, not escape_href. The escape_href function does url percent-encoding.) |
That explains everything haha. |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
…ng, r=<try> librustdoc: Use `pulldown-cmark-escape` for HTML escaping Implementation of `@notriddle` 's [suggestion](rust-lang#137274 (comment)). Somewhat related to rust-lang#137274 , but the two PRs should be complementary. Local perf results look like a nice improvement! (so would love a perf run on the CI)
Finished benchmarking commit (69f611a): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 2.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -4.3%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 773.063s -> 773.308s (0.03%) |
Perf regression is unfortunate, but not surprising. I'm hoping it's acceptable for now, I think I can win it back with #137285 and future PRs. |
I'd like to see some of the planned improvements added to this PR. Then we can do another perf run and see if they make up the difference. |
Spent quite a while trying to mitigate the perf regression, to no avail. |
…ng, r=GuillaumeGomez librustdoc: Use `pulldown-cmark-escape` for HTML escaping Implementation of `@notriddle` 's [suggestion](rust-lang#137274 (comment)). Somewhat related to rust-lang#137274 , but the two PRs should be complementary. Local perf results look like a nice improvement! (so would love a perf run on the CI)
…llaumeGomez librustdoc: Use `pulldown-cmark-escape` for HTML escaping Implementation of `@notriddle` 's [suggestion](rust-lang/rust#137274 (comment)). Somewhat related to #137274 , but the two PRs should be complementary. Local perf results look like a nice improvement! (so would love a perf run on the CI)
…llaumeGomez librustdoc: Use `pulldown-cmark-escape` for HTML escaping Implementation of `@notriddle` 's [suggestion](rust-lang/rust#137274 (comment)). Somewhat related to #137274 , but the two PRs should be complementary. Local perf results look like a nice improvement! (so would love a perf run on the CI)
…llaumeGomez librustdoc: Use `pulldown-cmark-escape` for HTML escaping Implementation of `@notriddle` 's [suggestion](rust-lang/rust#137274 (comment)). Somewhat related to #137274 , but the two PRs should be complementary. Local perf results look like a nice improvement! (so would love a perf run on the CI)
Inspired by this comment by @aDotInTheVoid .
Makes
Escape
andEscapeBodyText
accept anyimpl fmt::Display
, instead of a&str
, which allows us to avoid a few interimString
allocations.This opens up room for more lazifying, but I'll keep those for a separate PR.
Unfortunately, I think there might be a hit to performance because of the double vtable-indirection caused by wrapping a
fmt::Formatter
in another one, but I think that I should be able to gain that perf back by doing more lazy printing (either the small things improvements I made in this PR, or in later ones)Probably better to review each commit individually.