From a6d93be13eb5da5494e025a1486584bcac0274c5 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 26 Oct 2023 16:07:34 +0200 Subject: [PATCH 1/3] Benchmark crate for core features --- .github/workflows/benchmark-core.yml | 71 ++++++++++++++ .github/workflows/post-benchmark-core.yml | 100 +++++++++++++++++++ Cargo.lock | 112 +++++++++++++++++++++- tools/benchmark-core/Cargo.toml | 14 +++ tools/benchmark-core/benches/vnode.rs | 27 ++++++ 5 files changed, 321 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/benchmark-core.yml create mode 100644 .github/workflows/post-benchmark-core.yml create mode 100644 tools/benchmark-core/Cargo.toml create mode 100644 tools/benchmark-core/benches/vnode.rs diff --git a/.github/workflows/benchmark-core.yml b/.github/workflows/benchmark-core.yml new file mode 100644 index 00000000000..f9277e4c385 --- /dev/null +++ b/.github/workflows/benchmark-core.yml @@ -0,0 +1,71 @@ +--- +name: Benchmark - core + +on: + pull_request: + branches: [master] + paths: + - .github/workflows/benchmark-core.yml + - "packages/yew/**" + - "tools/benchmark-core/**" + +jobs: + benchmark-core: + name: Benchmark - core + runs-on: ubuntu-latest + + steps: + - name: Checkout master + uses: actions/checkout@v3 + with: + repository: "yewstack/yew" + ref: master + path: yew-master + + - name: Checkout pull request + uses: actions/checkout@v3 + with: + path: current-pr + + - name: Setup toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + + - name: Restore Rust cache for master + uses: Swatinem/rust-cache@v2 + with: + working-directory: yew-master + key: master + + - name: Restore Rust cache for current pull request + uses: Swatinem/rust-cache@v2 + with: + working-directory: current-pr + key: pr + + - name: Run pull request benchmark + run: cargo bench -q > ../output.log + working-directory: current-pr/tools/benchmark-core + + - name: Run master benchmark + run: cargo bench -q > ../output.log + continue-on-error: true + working-directory: yew-master/tools/benchmark-core + + - name: Make sure master's output log exists + run: touch yew-master/tools/output.log + + - name: Write Pull Request ID + run: | + echo "${{ github.event.number }}" > .PR_NUMBER + + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: benchmark-core + path: | + .PR_NUMBER + yew-master/tools/output.log + current-pr/tools/output.log + retention-days: 1 diff --git a/.github/workflows/post-benchmark-core.yml b/.github/workflows/post-benchmark-core.yml new file mode 100644 index 00000000000..ff011542164 --- /dev/null +++ b/.github/workflows/post-benchmark-core.yml @@ -0,0 +1,100 @@ +--- +name: Post Comment for Benchmark - core + +on: + workflow_run: + workflows: ["Benchmark - core"] + types: + - completed + +jobs: + post-benchmark-core: + if: github.event.workflow_run.event == 'pull_request' + name: Post Comment on Pull Request + runs-on: ubuntu-latest + + steps: + - name: Download Repository + uses: actions/checkout@v3 + + - name: Download Artifact + uses: Legit-Labs/action-download-artifact@v2 + with: + github_token: "${{ secrets.GITHUB_TOKEN }}" + workflow: benchmark-core.yml + run_id: ${{ github.event.workflow_run.id }} + name: benchmark-core + path: "benchmark-core/" + + - name: Make pull request comment + run: | + cat - >>comment.txt <>comment.txt + cat - >>comment.txt <> comment.txt + ``` + EOF + cat benchmark-core/current-pr/tools/output.json >>comment.txt + cat - >>comment.txt <> $GITHUB_ENV + + - name: Post Comment + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + + const commentInfo = { + ...context.repo, + issue_number: ${{ env.PR_NUMBER }}, + }; + + const comment = { + ...commentInfo, + body: fs.readFileSync("comment.txt", 'utf-8'), + }; + + function isCommentByBot(comment) { + return comment.user.type === "Bot" && comment.body.includes("### Benchmark - core"); + } + + let commentId = null; + const comments = (await github.rest.issues.listComments(commentInfo)).data; + for (let i = comments.length; i--; ) { + const c = comments[i]; + if (isCommentByBot(c)) { + commentId = c.id; + break; + } + } + + if (commentId) { + try { + await github.rest.issues.updateComment({ + ...context.repo, + comment_id: commentId, + body: comment.body, + }); + } catch (e) { + commentId = null; + } + } + + if (!commentId) { + await github.rest.issues.createComment(comment); + } diff --git a/Cargo.lock b/Cargo.lock index 7e7f4c2477b..08dc1cfb29c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -239,6 +239,14 @@ dependencies = [ "serde", ] +[[package]] +name = "benchmark-core" +version = "0.1.0" +dependencies = [ + "divan", + "yew", +] + [[package]] name = "benchmark-ssr" version = "0.1.0" @@ -402,6 +410,7 @@ dependencies = [ "anstyle", "clap_lex", "strsim", + "terminal_size", ] [[package]] @@ -462,6 +471,12 @@ dependencies = [ "yew", ] +[[package]] +name = "condtype" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" + [[package]] name = "console" version = "0.15.7" @@ -515,6 +530,17 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "core_affinity" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622892f5635ce1fc38c8f16dfc938553ed64af482edb5e150bf4caedbfcb2304" +dependencies = [ + "libc", + "num_cpus", + "winapi", +] + [[package]] name = "counter" version = "0.1.1" @@ -661,6 +687,31 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "divan" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9fe20b31e5a6a2c689cb9cd6b8ab3e1b417536b2369830b037acfee34b11469" +dependencies = [ + "clap", + "condtype", + "core_affinity", + "divan-macros", + "linkme", + "regex-lite", +] + +[[package]] +name = "divan-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c41656525d3cbca56bc91ca045ffb591b7b7d7bd7453750b63bacc35c46f3cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "dyn_create_destroy_apps" version = "0.1.0" @@ -1704,7 +1755,7 @@ checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", - "rustix", + "rustix 0.37.25", "windows-sys 0.48.0", ] @@ -1866,12 +1917,38 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linkme" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ed2ee9464ff9707af8e9ad834cffa4802f072caad90639c583dd3c62e6e608" +dependencies = [ + "linkme-impl", +] + +[[package]] +name = "linkme-impl" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba125974b109d512fccbc6c0244e7580143e460895dfd6ea7f8bbb692fd94396" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "linux-raw-sys" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +[[package]] +name = "linux-raw-sys" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" + [[package]] name = "lipsum" version = "0.9.0" @@ -2417,6 +2494,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-lite" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b661b2f27137bdbc16f00eda72866a92bb28af1753ffbd56744fb6e2e9cd8e" + [[package]] name = "regex-syntax" version = "0.8.2" @@ -2509,7 +2592,20 @@ dependencies = [ "errno", "io-lifetimes", "libc", - "linux-raw-sys", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustix" +version = "0.38.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys 0.4.10", "windows-sys 0.48.0", ] @@ -2877,7 +2973,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall", - "rustix", + "rustix 0.37.25", "windows-sys 0.48.0", ] @@ -2890,6 +2986,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "terminal_size" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix 0.38.13", + "windows-sys 0.48.0", +] + [[package]] name = "thiserror" version = "1.0.50" diff --git a/tools/benchmark-core/Cargo.toml b/tools/benchmark-core/Cargo.toml new file mode 100644 index 00000000000..871323c0700 --- /dev/null +++ b/tools/benchmark-core/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "benchmark-core" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[[bench]] +name = "vnode" +harness = false + +[dependencies] +divan = "0.1.0" +yew = { path = "../../packages/yew" } diff --git a/tools/benchmark-core/benches/vnode.rs b/tools/benchmark-core/benches/vnode.rs new file mode 100644 index 00000000000..2693282b48a --- /dev/null +++ b/tools/benchmark-core/benches/vnode.rs @@ -0,0 +1,27 @@ +use yew::prelude::*; + +fn main() { + divan::main(); +} + +#[function_component] +fn Stuff(_: &()) -> Html { + html! { +

{"A custom component"}

+ } +} + +#[divan::bench(sample_size = 10000000)] +fn vnode_clone(bencher: divan::Bencher) { + let html = html! { +
+ {"Hello"} + {"World"} + +
+ }; + + bencher.bench_local(move || { + let _ = divan::black_box(html.clone()); + }); +} From b36bfc869a098d5b34998225165d821738ba0ba3 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 26 Oct 2023 16:10:47 +0200 Subject: [PATCH 2/3] Fix incorrectly interpreted backticks --- .github/workflows/post-benchmark-core.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/post-benchmark-core.yml b/.github/workflows/post-benchmark-core.yml index ff011542164..d5567375f56 100644 --- a/.github/workflows/post-benchmark-core.yml +++ b/.github/workflows/post-benchmark-core.yml @@ -31,17 +31,17 @@ jobs: cat - >>comment.txt <>comment.txt cat - >>comment.txt <> comment.txt - ``` + \`\`\` EOF cat benchmark-core/current-pr/tools/output.json >>comment.txt cat - >>comment.txt < Date: Fri, 27 Oct 2023 14:13:17 +0200 Subject: [PATCH 3/3] Add VSuspense node in benchmark --- tools/benchmark-core/benches/vnode.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/benchmark-core/benches/vnode.rs b/tools/benchmark-core/benches/vnode.rs index 2693282b48a..ab42bbac211 100644 --- a/tools/benchmark-core/benches/vnode.rs +++ b/tools/benchmark-core/benches/vnode.rs @@ -18,6 +18,9 @@ fn vnode_clone(bencher: divan::Bencher) { {"Hello"} {"World"} + + + };