-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Migrate rustdoc from Tera to Askama #92526
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
Let's check perf. @bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 05465c2f5081b3d866854d74745029f0bace4b63 with merge e9be93a5f7d0a32ad8a9f6a1794ee49ef250d8fa... |
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 for working on this! Overall looks great. A few questions below.
☀️ Try build successful - checks-actions |
Queued e9be93a5f7d0a32ad8a9f6a1794ee49ef250d8fa with parent ddabe07, future comparison URL. |
@@ -143,8 +139,7 @@ pub(super) fn print_item( | |||
src_href: src_href.as_deref(), | |||
}; | |||
|
|||
let teractx = tera::Context::from_serialize(item_vars).unwrap(); | |||
let heading = templates.render("print_item.html", &teractx).unwrap(); | |||
let heading = item_vars.render().unwrap(); |
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.
A further performance improvement here would be to make sure that Buffer
impls core::fmt::Write
, in which case we could use render_into(buf)
rather than render()
, avoiding the allocation of a temporary String
here. Buffer
internally seems to just hold a String
and it has write_str()
and write_fmt()
methods already, so perhaps it would make sense to implement that trait? I'm not sure how big/relevant the performance improvement would be.
Finished benchmarking commit (e9be93a5f7d0a32ad8a9f6a1794ee49ef250d8fa): comparison url. Summary: This change led to very large relevant improvements 🎉 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking 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 led to changes in compiler perf. @bors rollup=never |
Looks like this easily wins back performance from #89695 and thus fixes #89732:
It looks like it's even substantially better than the situation before using Tera. |
So performance is great, code changes look good. Can you confirm that the generated HTML files size doesn't change (before and after this PR) please? |
Can you recommend an easy way/entry point on how/where to check that? |
Sure! So first, use |
@@ -7,20 +7,20 @@ | |||
<meta name="description" content="{{page.description}}"> {#- -#} | |||
<meta name="keywords" content="{{page.keywords}}"> {#- -#} | |||
<title>{{page.title}}</title> {#- -#} |
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.
Is there a way to get Askama to automatically strip the extra space rather than having to use {#- -#}
all over the place? This is one of my annoyances with templates, and it seems like it should theoretically be solvable.
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.
There is not currently. Askama is a general-purpose text templating mechanism, and the "extra space" is only useless in the particular context of writing out HTML. I don't know the exact details of how reducing whitespace in a string serialization of the HTML DOM will affect that DOM, but if there is a reliable algorithm to implement that, I'd suggest you open an issue against Askama to discuss how we might support that.
(For example, one way I might imagine doing it is by stripping any whitespace after a newline, but that doesn't remove all the whitespace the {#- -#}
currently remove because it leaves the newlines themselves. However, if you strip the newlines themselves you would invalidate content like <img src="foo"\nalt="foo">
. So solving this optimally seems like a decently hard problem.)
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.
At least stripping the extra spaces after the newline seems like it'd be good enough to me. Sometimes the newlines can be helpful for debugging the HTML too.
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 don't think I will have time to write code for this, but I'm happy to discuss how it could be implemented and review the 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.
One of the Askama team members submitted a PR for something like this today: djc/askama#598.
What do the errors look like when a template parameter is used incorrectly? E.g., what's the error when you try to iterate over an integer in a template? |
The errors are somewhat painful: you get a normal compiler error but with the span pointing to the |
Building the std docs this way errors out for me:
|
Ah right, sometimes for whatever reason it just doesn't build. Use I was sure that this issue was fixed though... So weird. |
That looks like you haven't built the standard library yet, which is strange since I thought x.py should build it before building rustdoc ... does |
It's in the build requirements normally as you can see here. |
Hmm... I wonder if there's a way you could attach the spans to non-Rust code by doing something like const _: &str = include_str!("the_template.html"); Then, the template source code would be part of the |
Why did you move the templates from |
⌛ Testing commit ef96d57 with merge e038d9166b04292cd4f8f0ed1091ae0163dfa25b... |
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (e916815): comparison url. Summary: This change led to very large relevant improvements 🎉 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
Fix a missing dot in the main item heading This pull-request fix a missing `·` in the item header ~~and also make use of ` ` to explicit that the spaces are mandatory~~. | Before | After | | --- | --- | | ![image](https://user-images.githubusercontent.com/3616612/149393966-7cca6dc5-9a62-47fa-8c9c-18f936d43aa9.png) | ![image](https://user-images.githubusercontent.com/3616612/149393869-5ffd6e44-d91c-4ece-b69e-d103304f6626.png) | PS: This was introduce yesterday by rust-lang#92526 (the migration from Tera to Askama) and is not currently observable in the nightly doc.
Fix a missing dot in the main item heading This pull-request fix a missing `·` in the item header ~~and also make use of ` ` to explicit that the spaces are mandatory~~. | Before | After | | --- | --- | | ![image](https://user-images.githubusercontent.com/3616612/149393966-7cca6dc5-9a62-47fa-8c9c-18f936d43aa9.png) | ![image](https://user-images.githubusercontent.com/3616612/149393869-5ffd6e44-d91c-4ece-b69e-d103304f6626.png) | PS: This was introduce yesterday by rust-lang#92526 (the migration from Tera to Askama) and is not currently observable in the nightly doc.
Fix a missing dot in the main item heading This pull-request fix a missing `·` in the item header ~~and also make use of ` ` to explicit that the spaces are mandatory~~. | Before | After | | --- | --- | | ![image](https://user-images.githubusercontent.com/3616612/149393966-7cca6dc5-9a62-47fa-8c9c-18f936d43aa9.png) | ![image](https://user-images.githubusercontent.com/3616612/149393869-5ffd6e44-d91c-4ece-b69e-d103304f6626.png) | PS: This was introduce yesterday by rust-lang#92526 (the migration from Tera to Askama) and is not currently observable in the nightly doc.
…=notriddle Move back templates into html folder Follow-up of rust-lang#92526. r? `@notriddle`
See #84419.
Should probably get a benchmarking run to verify if it has the intended effect on rustdoc performance.
cc @jsha @jyn514.