diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock index 306c9de..c1bc4ab 100644 --- a/.github/workflows/actions.lock +++ b/.github/workflows/actions.lock @@ -14,7 +14,7 @@ workflows: - 'baptiste0928/cargo-install@v3.5.0' - 'codecov/codecov-action@v7.1.1' - 'codecov/test-results-action@v1.2.1' - - 'codspeedhq/action@v5.0.0' + - 'codspeedhq/action@v5.6.3' - 'dtolnay/rust-toolchain@v1' - 'embarkstudios/cargo-deny-action@v2.1.1' - 'fsfe/reuse-action@v6.0.0' @@ -103,9 +103,9 @@ dependencies: commit: 'sha1-0fa95f0e1eeaafde2c782583b36b28ad0d8c77d3' owner_id: 8226205 repo_id: 761956558 - 'codspeedhq/action@v5.0.0': - ref: 'v5.0.0' - commit: 'sha1-f87ba88d8df49f904707c82ddc254bc791b049f5' + 'codspeedhq/action@v5.6.3': + ref: 'v5.6.3' + commit: 'sha1-af75f77f17a054769abefaa42fe8dc2975469b5f' owner_id: 116658140 repo_id: 561699778 uses: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c02b6f..fe01a06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -219,9 +219,10 @@ jobs: needs: [clippy, docs] runs-on: ubuntu-latest timeout-minutes: 30 - continue-on-error: true permissions: contents: read + # OpenID Connect authentication with CodSpeed; no token secret needed. + id-token: write steps: - uses: actions/checkout@v7.0.1 with: @@ -230,12 +231,14 @@ jobs: - uses: taiki-e/install-action@v2.90.5 with: tool: cargo-codspeed@6.0.0 - - run: cargo codspeed build -p wl-size -p wl-check + - name: Build the benchmarks + run: >- + cargo codspeed build -m simulation --locked + -p wl-size -p wl-check -p wl-html -p wl-css -p wl-js -p wl-profile - name: Run the benchmarks - uses: CodSpeedHQ/action@v5.0.0 + uses: CodSpeedHQ/action@v5.6.3 with: mode: simulation - token: ${{ secrets.CODSPEED_TOKEN }} run: cargo codspeed run pages: diff --git a/Cargo.lock b/Cargo.lock index bf2828b..6028c9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,15 +19,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "alloca" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5a7d05ea6aea7e9e64d25b9156ba2fee3fdd659e34e41063cd2fc7cd020d7f4" -dependencies = [ - "cc", -] - [[package]] name = "allocator-api2" version = "0.2.21" @@ -99,6 +90,21 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + [[package]] name = "autocfg" version = "1.5.1" @@ -264,12 +270,78 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" +[[package]] +name = "codspeed" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7c21807b937b8e535f2745cd83c525fc250524021cd662b9ba4d3e399bb504" +dependencies = [ + "anyhow", + "cc", + "colored", + "getrandom", + "glob", + "nix", + "serde", + "serde_json", + "statrs", +] + +[[package]] +name = "codspeed-criterion-compat" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a14939cf9e46182bdfbf6de618a8a110361c15a27eccff8f5ad4380249e9c14" +dependencies = [ + "clap", + "codspeed", + "codspeed-criterion-compat-walltime", + "colored", + "regex", +] + +[[package]] +name = "codspeed-criterion-compat-walltime" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af785573a72d17af663e661a45e1d617a2bab9f3a13a219ca0ae6ef9412ea1d8" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "codspeed", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + [[package]] name = "colorchoice" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" +[[package]] +name = "colored" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34" +dependencies = [ + "windows-sys", +] + [[package]] name = "compact_str" version = "0.10.0" @@ -319,36 +391,11 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "criterion" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "950046b2aa2492f9a536f5f4f9a3de7b9e2476e575e05bd6c333371add4d98f3" -dependencies = [ - "alloca", - "anes", - "cast", - "ciborium", - "clap", - "criterion-plot", - "itertools", - "num-traits", - "oorandom", - "page_size", - "plotters", - "rayon", - "regex", - "serde", - "serde_json", - "tinytemplate", - "walkdir", -] - [[package]] name = "criterion-plot" -version = "0.8.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8d80a2f4f5b554395e47b5d8305bc3d27813bacb73493eb1001e8f76dae29ea" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", "itertools", @@ -600,6 +647,12 @@ dependencies = [ "r-efi", ] +[[package]] +name = "glob" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" + [[package]] name = "globset" version = "0.4.21" @@ -639,6 +692,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" + [[package]] name = "html5ever" version = "0.40.1" @@ -799,6 +858,17 @@ dependencies = [ "serde_core", ] +[[package]] +name = "is-terminal" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -807,9 +877,9 @@ checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "itertools" -version = "0.13.0" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] @@ -1212,16 +1282,6 @@ dependencies = [ "zmij_ecma", ] -[[package]] -name = "page_size" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "parking_lot" version = "0.12.5" @@ -1732,6 +1792,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "statrs" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a3fe7c28c6512e766b0874335db33c94ad7b8f9054228ae1c2abd47ce7d335e" +dependencies = [ + "approx", + "num-traits", +] + [[package]] name = "string_cache" version = "0.11.0" @@ -2128,22 +2198,6 @@ dependencies = [ "string_cache_codegen", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - [[package]] name = "winapi-util" version = "0.1.11" @@ -2153,12 +2207,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows" version = "0.62.2" @@ -2288,7 +2336,7 @@ checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" name = "wl-check" version = "0.1.0" dependencies = [ - "criterion", + "codspeed-criterion-compat", "masterror", "schemars", "serde", @@ -2333,6 +2381,7 @@ dependencies = [ name = "wl-css" version = "0.1.0" dependencies = [ + "codspeed-criterion-compat", "masterror", "wl-core", "wl-profile", @@ -2342,6 +2391,7 @@ dependencies = [ name = "wl-html" version = "0.1.0" dependencies = [ + "codspeed-criterion-compat", "html5ever", "masterror", "tendril", @@ -2353,6 +2403,7 @@ dependencies = [ name = "wl-js" version = "0.1.0" dependencies = [ + "codspeed-criterion-compat", "masterror", "oxc_allocator", "oxc_ast", @@ -2382,6 +2433,7 @@ dependencies = [ name = "wl-profile" version = "0.1.0" dependencies = [ + "codspeed-criterion-compat", "masterror", "serde", "toml", @@ -2391,7 +2443,7 @@ dependencies = [ name = "wl-size" version = "0.1.0" dependencies = [ - "criterion", + "codspeed-criterion-compat", "flate2", "libz-sys", "masterror", diff --git a/Cargo.toml b/Cargo.toml index 0797cb7..17e62be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ version = "0.1.0" [workspace.dependencies] clap = { version = "4", features = ["derive"] } -criterion = "0.8" +criterion = { package = "codspeed-criterion-compat", version = "6.0.0" } flate2 = { version = "1", default-features = false } globset = "0.4" html5ever = "0.40" diff --git a/README.md b/README.md index 7037eca..9f58a0b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ caught before you send. [![CI](https://github.com/RAprogramm/widgetlint/actions/workflows/ci.yml/badge.svg)](https://github.com/RAprogramm/widgetlint/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/RAprogramm/widgetlint/branch/main/graph/badge.svg)](https://codecov.io/gh/RAprogramm/widgetlint) -[![CodSpeed](https://img.shields.io/endpoint?url=https://app.codspeed.io//badge.json)](https://app.codspeed.io/RAprogramm/widgetlint?utm_source=badge) +[![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://app.codspeed.io/RAprogramm/widgetlint?utm_source=badge) [![release](https://img.shields.io/github/v/release/RAprogramm/widgetlint?label=release)](https://github.com/RAprogramm/widgetlint/releases/latest) [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![REUSE](https://api.reuse.software/badge/github.com/RAprogramm/widgetlint)](https://api.reuse.software/info/github.com/RAprogramm/widgetlint) diff --git a/crates/wl-check/benches/check.rs b/crates/wl-check/benches/check.rs index cdb64c6..0ff8001 100644 --- a/crates/wl-check/benches/check.rs +++ b/crates/wl-check/benches/check.rs @@ -1,6 +1,12 @@ // SPDX-FileCopyrightText: 2026 RAprogramm // SPDX-License-Identifier: MIT +#![allow( + missing_docs, + clippy::significant_drop_tightening, + reason = "the CodSpeed criterion_group! and criterion_main! macros expand to undocumented \ + functions that hold the Criterion value until the end of the group" +)] #![allow( clippy::expect_used, clippy::literal_string_with_formatting_args, diff --git a/crates/wl-css/Cargo.toml b/crates/wl-css/Cargo.toml index 2599766..94c1d31 100644 --- a/crates/wl-css/Cargo.toml +++ b/crates/wl-css/Cargo.toml @@ -14,7 +14,12 @@ wl-core.workspace = true wl-profile.workspace = true [dev-dependencies] +criterion.workspace = true masterror.workspace = true +[[bench]] +name = "css" +harness = false + [lints] workspace = true diff --git a/crates/wl-css/benches/css.rs b/crates/wl-css/benches/css.rs new file mode 100644 index 0000000..fe3a7a9 --- /dev/null +++ b/crates/wl-css/benches/css.rs @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: 2026 RAprogramm +// SPDX-License-Identifier: MIT + +#![allow( + missing_docs, + clippy::significant_drop_tightening, + reason = "the CodSpeed criterion_group! and criterion_main! macros expand to undocumented \ + functions that hold the Criterion value until the end of the group" +)] +#![allow( + clippy::expect_used, + clippy::literal_string_with_formatting_args, + reason = "benches must fail loudly and embed CSS literals whose braces are not format arguments" +)] + +//! Benchmarks for the span-precise CSS scanner and rules. + +use std::hint::black_box; + +use criterion::{Criterion, criterion_group, criterion_main}; + +fn stylesheet(filler: &str, size: usize) -> String { + let mut out = String::with_capacity(size); + while out.len() < size { + out.push_str(filler); + } + out.truncate(size); + out +} + +fn bench_check(c: &mut Criterion) { + let profile = wl_profile::profile_1().expect("the embedded profile must parse"); + let mut group = c.benchmark_group("css_check"); + for (name, filler, size) in [ + ("simple", ".a{color:red;margin:0}\n", 1024_usize), + ( + "nested", + "@media (max-width:600px){.row>.cell:hover{padding:4px 8px;display:flex}}\n", + 8192 + ), + ( + "violations", + ".x{position:fixed;background:url(http://x.example/a.png);unknown-prop:1}\n", + 16384 + ) + ] { + let css = stylesheet(filler, size); + group.bench_function(name, |b| { + b.iter(|| wl_css::check(black_box(&css), black_box(0), black_box(&profile))); + }); + } + group.finish(); +} + +criterion_group!(benches, bench_check); +criterion_main!(benches); diff --git a/crates/wl-html/Cargo.toml b/crates/wl-html/Cargo.toml index b6d8fe5..0bd5acc 100644 --- a/crates/wl-html/Cargo.toml +++ b/crates/wl-html/Cargo.toml @@ -11,8 +11,13 @@ rust-version.workspace = true version.workspace = true [dev-dependencies] +criterion.workspace = true masterror.workspace = true +[[bench]] +name = "html" +harness = false + [lints] workspace = true diff --git a/crates/wl-html/benches/html.rs b/crates/wl-html/benches/html.rs new file mode 100644 index 0000000..298ce91 --- /dev/null +++ b/crates/wl-html/benches/html.rs @@ -0,0 +1,72 @@ +// SPDX-FileCopyrightText: 2026 RAprogramm +// SPDX-License-Identifier: MIT + +#![allow( + missing_docs, + clippy::significant_drop_tightening, + reason = "the CodSpeed criterion_group! and criterion_main! macros expand to undocumented \ + functions that hold the Criterion value until the end of the group" +)] +#![allow( + clippy::expect_used, + reason = "benches must fail loudly when the embedded profile is broken" +)] + +//! Benchmarks for HTML parsing with source spans and the HTML rules. + +use std::hint::black_box; + +use criterion::{Criterion, criterion_group, criterion_main}; + +const INPUTS: [(&str, &str, usize); 3] = [ + ( + "clean", + "
hello
\n", + 1024 + ), + ( + "attributes", + "\n", + 8192 + ), + ( + "violations", + "x\n", + 16384 + ) +]; + +fn widget(filler: &str, size: usize) -> String { + let mut out = String::with_capacity(size); + while out.len() < size { + out.push_str(filler); + } + out.truncate(size); + out +} + +fn bench_parse(c: &mut Criterion) { + let mut group = c.benchmark_group("html_parse"); + for (name, filler, size) in INPUTS { + let source = widget(filler, size); + group.bench_function(name, |b| { + b.iter(|| wl_html::parse(black_box(&source))); + }); + } + group.finish(); +} + +fn bench_check(c: &mut Criterion) { + let profile = wl_profile::profile_1().expect("the embedded profile must parse"); + let mut group = c.benchmark_group("html_check"); + for (name, filler, size) in INPUTS { + let source = widget(filler, size); + group.bench_function(name, |b| { + b.iter(|| wl_html::check(black_box(&source), black_box(&profile))); + }); + } + group.finish(); +} + +criterion_group!(benches, bench_parse, bench_check); +criterion_main!(benches); diff --git a/crates/wl-js/Cargo.toml b/crates/wl-js/Cargo.toml index f696a25..f999179 100644 --- a/crates/wl-js/Cargo.toml +++ b/crates/wl-js/Cargo.toml @@ -20,7 +20,12 @@ wl-core.workspace = true wl-profile.workspace = true [dev-dependencies] +criterion.workspace = true masterror.workspace = true +[[bench]] +name = "js" +harness = false + [lints] workspace = true diff --git a/crates/wl-js/benches/js.rs b/crates/wl-js/benches/js.rs new file mode 100644 index 0000000..e7b9c6c --- /dev/null +++ b/crates/wl-js/benches/js.rs @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: 2026 RAprogramm +// SPDX-License-Identifier: MIT + +#![allow( + missing_docs, + clippy::significant_drop_tightening, + reason = "the CodSpeed criterion_group! and criterion_main! macros expand to undocumented \ + functions that hold the Criterion value until the end of the group" +)] +#![allow( + clippy::expect_used, + reason = "benches must fail loudly when the embedded profile or a script is broken" +)] + +//! Benchmarks for the JavaScript rules on the oxc parser. + +use std::hint::black_box; + +use criterion::{Criterion, criterion_group, criterion_main}; + +/// Repeats whole statements only, so the script always parses. +fn script(filler: &str, size: usize) -> String { + let mut out = String::with_capacity(size); + while out.len() + filler.len() <= size { + out.push_str(filler); + } + out +} + +fn bench_check(c: &mut Criterion) { + let profile = wl_profile::profile_1().expect("the embedded profile must parse"); + let mut group = c.benchmark_group("js_check"); + for (name, filler, size) in [ + ("state", "state.count = state.count + 1;\n", 1024_usize), + ( + "functions", + "function tap(e) { const v = e.target.value; if (v > 1) { state.x = v * 2; } }\n", + 8192 + ), + ( + "violations", + "fetch('http://x.example'); eval('1'); document.cookie = 'a=1';\n", + 16384 + ) + ] { + let js = script(filler, size); + wl_js::check(&js, 0, &profile).expect("the bench script must parse"); + group.bench_function(name, |b| { + b.iter(|| wl_js::check(black_box(&js), black_box(0), black_box(&profile))); + }); + } + group.finish(); +} + +criterion_group!(benches, bench_check); +criterion_main!(benches); diff --git a/crates/wl-profile/Cargo.toml b/crates/wl-profile/Cargo.toml index c0029d8..c8a9f7f 100644 --- a/crates/wl-profile/Cargo.toml +++ b/crates/wl-profile/Cargo.toml @@ -10,6 +10,10 @@ repository.workspace = true rust-version.workspace = true version.workspace = true +[[bench]] +name = "profile" +harness = false + [lints] workspace = true @@ -17,3 +21,6 @@ workspace = true masterror.workspace = true serde.workspace = true toml.workspace = true + +[dev-dependencies] +criterion.workspace = true diff --git a/crates/wl-profile/benches/profile.rs b/crates/wl-profile/benches/profile.rs new file mode 100644 index 0000000..4d5704a --- /dev/null +++ b/crates/wl-profile/benches/profile.rs @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2026 RAprogramm +// SPDX-License-Identifier: MIT + +#![allow( + missing_docs, + clippy::significant_drop_tightening, + reason = "the CodSpeed criterion_group! and criterion_main! macros expand to undocumented \ + functions that hold the Criterion value until the end of the group" +)] + +//! Benchmarks for loading and validating the embedded profile. + +use criterion::{Criterion, criterion_group, criterion_main}; + +fn bench_profile(c: &mut Criterion) { + c.bench_function("profile_1_load", |b| { + b.iter(wl_profile::profile_1); + }); +} + +criterion_group!(benches, bench_profile); +criterion_main!(benches); diff --git a/crates/wl-size/benches/compress.rs b/crates/wl-size/benches/compress.rs index 9da39fe..14a96df 100644 --- a/crates/wl-size/benches/compress.rs +++ b/crates/wl-size/benches/compress.rs @@ -1,6 +1,12 @@ // SPDX-FileCopyrightText: 2026 RAprogramm // SPDX-License-Identifier: MIT +#![allow( + missing_docs, + clippy::significant_drop_tightening, + reason = "the CodSpeed criterion_group! and criterion_main! macros expand to undocumented \ + functions that hold the Criterion value until the end of the group" +)] #![allow( clippy::expect_used, reason = "benches must fail loudly on zlib errors"