Improve rendering speed by moving settings generation after theme rendering

This commit is contained in:
Guillaume Gomez 2024-08-15 16:13:53 +02:00
parent e0b0851ba8
commit 47f40d468a
3 changed files with 36 additions and 28 deletions

View File

@ -9,7 +9,8 @@
use clippy_lints::declared_lints::LINTS; use clippy_lints::declared_lints::LINTS;
use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED}; use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED};
use pulldown_cmark::{Options, Parser, html}; use pulldown_cmark::{Options, Parser, html};
use rinja::{Template, filters::Safe}; use rinja::Template;
use rinja::filters::Safe;
use serde::Deserialize; use serde::Deserialize;
use test_utils::IS_RUSTC_TEST_SUITE; use test_utils::IS_RUSTC_TEST_SUITE;
use ui_test::custom_flags::Flag; use ui_test::custom_flags::Flag;
@ -394,7 +395,7 @@ struct Renderer<'a> {
} }
impl<'a> Renderer<'a> { impl<'a> Renderer<'a> {
fn markdown(&self, input: &str) -> Safe<String> { fn markdown(input: &str) -> Safe<String> {
let parser = Parser::new_ext(input, Options::all()); let parser = Parser::new_ext(input, Options::all());
let mut html_output = String::new(); let mut html_output = String::new();
html::push_html(&mut html_output, parser); html::push_html(&mut html_output, parser);
@ -465,7 +466,11 @@ fn spawn() -> (Self, thread::JoinHandle<()>) {
.collect(); .collect();
metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id)); metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id));
fs::write("util/gh-pages/index.html", Renderer { lints: &metadata }.render().unwrap()).unwrap(); fs::write(
"util/gh-pages/index.html",
Renderer { lints: &metadata }.render().unwrap(),
)
.unwrap();
}); });
(Self { sender }, handle) (Self { sender }, handle)

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<!-- <!--
Welcome to a Clippy's lint list, at least the source code of it. If you are Welcome to a Clippy's lint list, at least the source code of it. If you are
interested in contributing to this website checkout `util/gh-pages/index.html` interested in contributing to this website checkout `util/gh-pages/index_template.html`
inside the rust-clippy repository. inside the rust-clippy repository.
Otherwise, have a great day =^.^= Otherwise, have a great day =^.^=
@ -164,7 +164,7 @@ Otherwise, have a great day =^.^=
</header> </header>
<div class="list-group lint-docs"> <div class="list-group lint-docs">
<div class="list-group-item lint-doc-md">{(markdown(lint.docs))}</div> <div class="list-group-item lint-doc-md">{(Self::markdown(lint.docs))}</div>
<div class="lint-additional-info-container"> <div class="lint-additional-info-container">
{# Applicability #} {# Applicability #}
<div class="lint-additional-info-item"> <div class="lint-additional-info-item">

View File

@ -46,17 +46,6 @@ function setTheme(theme, store) {
} }
} }
// loading the theme after the initial load
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
const theme = loadValue('theme');
if (prefersDark.matches && !theme) {
setTheme("coal", false);
} else {
setTheme(theme, false);
}
let disableShortcuts = loadValue('disable-shortcuts') === "true";
document.getElementById("disable-shortcuts").checked = disableShortcuts;
window.searchState = { window.searchState = {
timeout: null, timeout: null,
inputElem: document.getElementById("search-input"), inputElem: document.getElementById("search-input"),
@ -161,9 +150,6 @@ function handleShortcut(ev) {
} }
} }
document.addEventListener("keypress", handleShortcut);
document.addEventListener("keydown", handleShortcut);
function toggleElements(filter, value) { function toggleElements(filter, value) {
let needsUpdate = false; let needsUpdate = false;
let count = 0; let count = 0;
@ -271,13 +257,13 @@ const GROUPS_FILTER_DEFAULT = {
cargo: true, cargo: true,
complexity: true, complexity: true,
correctness: true, correctness: true,
deprecated: false,
nursery: true, nursery: true,
pedantic: true, pedantic: true,
perf: true, perf: true,
restriction: true, restriction: true,
style: true, style: true,
suspicious: true, suspicious: true,
deprecated: false,
}; };
const LEVEL_FILTERS_DEFAULT = { const LEVEL_FILTERS_DEFAULT = {
allow: true, allow: true,
@ -287,7 +273,6 @@ const LEVEL_FILTERS_DEFAULT = {
}; };
const APPLICABILITIES_FILTER_DEFAULT = { const APPLICABILITIES_FILTER_DEFAULT = {
Unspecified: true, Unspecified: true,
Unresolved: true,
MachineApplicable: true, MachineApplicable: true,
MaybeIncorrect: true, MaybeIncorrect: true,
HasPlaceholders: true, HasPlaceholders: true,
@ -570,9 +555,6 @@ function generateSearch() {
searchState.inputElem.addEventListener("paste", handleInputChanged); searchState.inputElem.addEventListener("paste", handleInputChanged);
} }
generateSettings();
generateSearch();
function scrollToLint(lintId) { function scrollToLint(lintId) {
const target = document.getElementById(lintId); const target = document.getElementById(lintId);
if (!target) { if (!target) {
@ -617,7 +599,28 @@ function parseURLFilters() {
} }
} }
// loading the theme after the initial load
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
const theme = loadValue('theme');
if (prefersDark.matches && !theme) {
setTheme("coal", false);
} else {
setTheme(theme, false);
}
let disableShortcuts = loadValue('disable-shortcuts') === "true";
// To prevent having a "flash", we give back time to the web browser to finish rendering with
// theme applied before finishing the rendering.
setTimeout(() => {
document.getElementById("disable-shortcuts").checked = disableShortcuts;
document.addEventListener("keypress", handleShortcut);
document.addEventListener("keydown", handleShortcut);
generateSettings();
generateSearch();
parseURLFilters(); parseURLFilters();
scrollToLintByURL(); scrollToLintByURL();
filters.filterLints(); filters.filterLints();
onEachLazy(document.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el)); onEachLazy(document.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el));
}, 0);