Benchmark crate for core features (#3487)

* Benchmark crate for core features

* Fix incorrectly interpreted backticks

* Add VSuspense node in benchmark
This commit is contained in:
Cecile Tonglet 2023-10-27 14:25:26 +02:00 committed by GitHub
parent 1b9d29464a
commit 22fd855052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 324 additions and 3 deletions

71
.github/workflows/benchmark-core.yml vendored Normal file
View File

@ -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

View File

@ -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 <<EOF
### Benchmark - core
#### Yew Master
\`\`\`
EOF
cat benchmark-core/yew-master/tools/output.json >>comment.txt
cat - >>comment.txt <<EOF
\`\`\`
#### Pull Request" >> comment.txt
\`\`\`
EOF
cat benchmark-core/current-pr/tools/output.json >>comment.txt
cat - >>comment.txt <<EOF
\`\`\`
EOF
- name: Read Pull Request ID
run: |
PR_NUMBER=$(cat "benchmark-core/.PR_NUMBER")
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "pr number invalid"
exit 1
fi
echo "PR_NUMBER=$PR_NUMBER" >> $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);
}

112
Cargo.lock generated
View File

@ -239,6 +239,14 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "benchmark-core"
version = "0.1.0"
dependencies = [
"divan",
"yew",
]
[[package]] [[package]]
name = "benchmark-ssr" name = "benchmark-ssr"
version = "0.1.0" version = "0.1.0"
@ -402,6 +410,7 @@ dependencies = [
"anstyle", "anstyle",
"clap_lex", "clap_lex",
"strsim", "strsim",
"terminal_size",
] ]
[[package]] [[package]]
@ -462,6 +471,12 @@ dependencies = [
"yew", "yew",
] ]
[[package]]
name = "condtype"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af"
[[package]] [[package]]
name = "console" name = "console"
version = "0.15.7" version = "0.15.7"
@ -515,6 +530,17 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" 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]] [[package]]
name = "counter" name = "counter"
version = "0.1.1" version = "0.1.1"
@ -661,6 +687,31 @@ dependencies = [
"crypto-common", "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]] [[package]]
name = "dyn_create_destroy_apps" name = "dyn_create_destroy_apps"
version = "0.1.0" version = "0.1.0"
@ -1704,7 +1755,7 @@ checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
dependencies = [ dependencies = [
"hermit-abi 0.3.1", "hermit-abi 0.3.1",
"io-lifetimes", "io-lifetimes",
"rustix", "rustix 0.37.25",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -1866,12 +1917,38 @@ dependencies = [
"vcpkg", "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]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.3.8" version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]]
name = "linux-raw-sys"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f"
[[package]] [[package]]
name = "lipsum" name = "lipsum"
version = "0.9.0" version = "0.9.0"
@ -2417,6 +2494,12 @@ dependencies = [
"regex-syntax", "regex-syntax",
] ]
[[package]]
name = "regex-lite"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30b661b2f27137bdbc16f00eda72866a92bb28af1753ffbd56744fb6e2e9cd8e"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.8.2" version = "0.8.2"
@ -2509,7 +2592,20 @@ dependencies = [
"errno", "errno",
"io-lifetimes", "io-lifetimes",
"libc", "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", "windows-sys 0.48.0",
] ]
@ -2877,7 +2973,7 @@ dependencies = [
"cfg-if", "cfg-if",
"fastrand", "fastrand",
"redox_syscall", "redox_syscall",
"rustix", "rustix 0.37.25",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -2890,6 +2986,16 @@ dependencies = [
"winapi-util", "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]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.50" version = "1.0.50"

View File

@ -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" }

View File

@ -0,0 +1,30 @@
use yew::prelude::*;
fn main() {
divan::main();
}
#[function_component]
fn Stuff(_: &()) -> Html {
html! {
<p>{"A custom component"}</p>
}
}
#[divan::bench(sample_size = 10000000)]
fn vnode_clone(bencher: divan::Bencher) {
let html = html! {
<div class={classes!("hello-world")}>
<span>{"Hello"}</span>
<strong style="color:red">{"World"}</strong>
<Stuff />
<Suspense fallback={html!("Loading...")}>
<Stuff />
</Suspense>
</div>
};
bencher.bench_local(move || {
let _ = divan::black_box(html.clone());
});
}