Skip to content
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

rustdoc: preload fonts #91170

Closed
wants to merge 1 commit into from
Closed

rustdoc: preload fonts #91170

wants to merge 1 commit into from

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Nov 24, 2021

Follow-up from #82315.

I noticed that font loading was so slow that even when loading from local disk, we get a flash of unstyled text (FOUT) followed by a reflow when the fonts load. With this change, we reliably get the appropriate fonts in the first render pass when loading locally, and we get it some of the time when loading from a website.

This only preloads woff2 versions. According to https://caniuse.com/?search=preload and https://caniuse.com/?search=woff2, all browsers that support preload also support woff2, so this is fine; we will never load two copies of a font.

Don't preload italic font faces because they aren't used on all pages.

Demo: https://rustdoc.crud.net/jsha/preload-fonts/std/string/struct.String.html

Don't preload italic font faces because they aren't used on all pages,
and when they are used, they are used sparingly so it's okay if they are
slower to load.
@jsha jsha added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-ui Area: rustdoc UI (generated HTML) labels Nov 24, 2021
@rust-highfive
Copy link
Collaborator

r? @GuillaumeGomez

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 24, 2021
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  IMAGE: x86_64-gnu-tools
##[endgroup]
From https://github.com/rust-lang/rust
 * branch              master     -> FETCH_HEAD
Searching for toolstate changes between de4b242e1e2143f549f25ac5a8f7de9d902ef3b4 and 5c1d73dbf6199b7b0d89c53f9bb4285741ed8b20
Rustdoc was updated
##[group]Run src/ci/scripts/verify-channel.sh
src/ci/scripts/verify-channel.sh
shell: /bin/bash --noprofile --norc -e -o pipefail {0}
env:
---
F (50/53)
............        (53/53)


/checkout/src/test/rustdoc-gui/toggle-click-deadspace.goml toggle-click-deadspace... FAILED
[ERROR] (line 8) Error: Evaluation failed: assert didn't fail: for command `assert-attribute-false: (".impl-items .rustdoc-toggle", {"open": ""})`



command did not execute successfully: "/node-v14.4.0-linux-x64/bin/node" "/checkout/src/tools/rustdoc-gui/tester.js" "--jobs" "16" "--doc-folder" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc" "--tests-folder" "/checkout/src/test/rustdoc-gui"


Build completed unsuccessfully in 0:00:19

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 24, 2021
…eGomez

Fix toggle-click-deadspace rustdoc-gui test

In rust-lang#91103 I introduced a rustdoc-gui test for clicks on toggles. I introduced some documentation on a method in lib2/struct.Foo.html so there would be something to toggle, but accidentally left the test checking test_docs/struct.Foo.html. That caused the test to reliably fail.

I'm not sure how that test got past GitHub Actions and bors, but it's manifesting in test failures at rust-lang#91062 (comment) and rust-lang#91170 (comment).

This fixes by pointing at the right file.

r? `@GuillaumeGomez`
@jsha jsha closed this Nov 25, 2021
@jsha jsha reopened this Nov 25, 2021
@jsha
Copy link
Contributor Author

jsha commented Dec 2, 2021

@GuillaumeGomez ping on this. :-)

@GuillaumeGomez
Copy link
Member

This is indeed much nicer, thanks a lot!

@bors: r+

@bors
Copy link
Contributor

bors commented Dec 2, 2021

📌 Commit 4198fac has been approved by GuillaumeGomez

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 2, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 3, 2021
rustdoc: preload fonts

Follow-up from rust-lang#82315.

I noticed that font loading was so slow that even when loading from local disk, we get a flash of unstyled text (FOUT) followed by a reflow when the fonts load. With this change, we reliably get the appropriate fonts in the first render pass when loading locally, and we get it some of the time when loading from a website.

This only preloads woff2 versions. According to https://caniuse.com/?search=preload and https://caniuse.com/?search=woff2, all browsers that support preload also support woff2, so this is fine; we will never load two copies of a font.

Don't preload italic font faces because they aren't used on all pages.

Demo: https://rustdoc.crud.net/jsha/preload-fonts/std/string/struct.String.html
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 3, 2021
rustdoc: preload fonts

Follow-up from rust-lang#82315.

I noticed that font loading was so slow that even when loading from local disk, we get a flash of unstyled text (FOUT) followed by a reflow when the fonts load. With this change, we reliably get the appropriate fonts in the first render pass when loading locally, and we get it some of the time when loading from a website.

This only preloads woff2 versions. According to https://caniuse.com/?search=preload and https://caniuse.com/?search=woff2, all browsers that support preload also support woff2, so this is fine; we will never load two copies of a font.

Don't preload italic font faces because they aren't used on all pages.

Demo: https://rustdoc.crud.net/jsha/preload-fonts/std/string/struct.String.html
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 3, 2021
…askrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#88906 (Implement write() method for Box<MaybeUninit<T>>)
 - rust-lang#90269 (Make `Option::expect` unstably const)
 - rust-lang#90854 (Type can be unsized and uninhabited)
 - rust-lang#91170 (rustdoc: preload fonts)
 - rust-lang#91273 (Fix ICE rust-lang#91268 by checking that the snippet ends with a `)`)
 - rust-lang#91381 (Android: -ldl must appear after -lgcc when linking)
 - rust-lang#91453 (Document Windows TLS drop behaviour)
 - rust-lang#91462 (Use try_normalize_erasing_regions in needs_drop)
 - rust-lang#91474 (suppress warning about set_errno being unused on DragonFly)
 - rust-lang#91483 (Sync rustfmt subtree)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Dec 3, 2021

☔ The latest upstream changes (presumably #91486) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 3, 2021
@pietroalbini
Copy link
Member

This has been merged into master by bors (in #91486), but GitHub didn't detect it for whatever reason. Closing.

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 7, 2023
…GuillaumeGomez

rustdoc: stop preloading Source Serif 4 Bold

According to rust-lang#91170, italic fonts are not preloaded because they're rarely used, but bold fonts are. This seems to be true of bold Source Code Pro and bold Fira Sans, but bold and italic Source Serif Pro seem to be equally heavily used.

This is, I assume, the result of using Fira Sans Bold and Source Code Bold headings, so you only get bold Serif text when the doc author uses strong `**` emphasis (or within certain kinds of tooltip, which shouldn't be preloaded because they only show up long after the page is loaded).

To check this, run these two commands in the browser console to measure how much they're used. The measurement is extremely rough, but it gets the idea across: the two styles are about equally popular.

    // count bold elements
    Array.prototype.slice.call(document.querySelectorAll("*")).filter(x => { const y = document.defaultView.getComputedStyle(x); return y.fontFamily.indexOf("Source Serif 4") !== -1 && y.fontWeight > 400 }).length
    // count italic elements
    Array.prototype.slice.call(document.querySelectorAll("*")).filter(x => { const y = document.defaultView.getComputedStyle(x); return y.fontFamily.indexOf("Source Serif 4") !== -1 && y.fontStyle == "italic" }).length

| URL          | Bold | Italic |
|--------------|-----:|-------:|
| [std]        |    2 |      9 |
| [Vec]        |    8 |     89 |
| [regex]      |   33 |     17 |
| [test_suite] |    0 |      0 |

[std]: https://doc.rust-lang.org/nightly/std/index.html
[Vec]: https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html
[regex]: https://docs.rs/regex/1.9.5/regex/index.html
[test_suite]: https://docs.rs/test-suite/3.2.9/test_suite/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: rustdoc UI (generated HTML) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants