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

Configurable Runtime #2772

Merged
merged 54 commits into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8dbf8aa
Adds Runtime.
futursolo Jul 1, 2022
3266319
Merge branch 'master' into local-runtime
futursolo Jul 1, 2022
eddec1d
A LocalRuntime.
futursolo Jul 1, 2022
a18d7d6
Add note.
futursolo Jul 1, 2022
2498542
Add SSR benchmark.
futursolo Jul 1, 2022
7d8a48b
Only create default runtime if no custom runtime is set.
futursolo Jul 1, 2022
d3121c7
Use jemalloc for benchmarking.
futursolo Jul 1, 2022
6f9b32a
Remove once_cell for web assembly.
futursolo Jul 1, 2022
8e72fcc
Add time.
futursolo Jul 1, 2022
7c65632
Fix wasm_bindgen.
futursolo Jul 1, 2022
75242b5
Adjust inlining.
futursolo Jul 1, 2022
1d6274c
Optimise benchmark output.
futursolo Jul 2, 2022
7437a4b
Optimise BufWriter.
futursolo Jul 2, 2022
f02d0e2
Add json output.
futursolo Jul 2, 2022
fa735f7
Add Benchmark Workflow.
futursolo Jul 2, 2022
74e0876
Remove local set from tests.
futursolo Jul 2, 2022
4db4134
Fix Workflow syntax.
futursolo Jul 3, 2022
2c318a1
Exclude benchmark from doc tests.
futursolo Jul 3, 2022
214b140
Adjust feature flags.
futursolo Jul 6, 2022
f2fcea2
Adds a pinned channel implementation.
futursolo Jul 6, 2022
406aed5
Make Send bound explicit.
futursolo Jul 6, 2022
76ce866
Implement on immutable reference.
futursolo Jul 6, 2022
0ba69be
Fix Sink close.
futursolo Jul 6, 2022
098728e
run_pinned -> spawn_pinned.
futursolo Jul 7, 2022
61dc8f8
Merge master into local-runtime
futursolo Jul 7, 2022
056a826
Add tests.
futursolo Jul 7, 2022
b61e016
Adjusts worker threads.
futursolo Jul 7, 2022
736b9b6
Fix workflow.
futursolo Jul 7, 2022
c9e8123
Remove futures-executor.
futursolo Jul 7, 2022
c7707bb
Cargo update.
futursolo Jul 7, 2022
2f8358e
Fix docs.
futursolo Jul 7, 2022
f064359
Update notice.
futursolo Jul 7, 2022
f55d87f
Fix docs.
futursolo Jul 7, 2022
ba335ae
Fix docs.
futursolo Jul 7, 2022
be4b23e
Switch to task spawning.
futursolo Jul 9, 2022
2235544
Use futures unordered instead of spawn_local.
futursolo Jul 9, 2022
4f51d5e
Switch to join_all.
futursolo Jul 9, 2022
0daa99b
Remove LocalPoolHandle.
futursolo Jul 17, 2022
e052184
Fix docs.
futursolo Jul 17, 2022
77d5e7a
Spawn a single task.
futursolo Jul 17, 2022
9c19ca2
Merge branch 'master' into local-runtime
futursolo Jul 18, 2022
b7531c3
Merge branch 'master' into local-runtime
futursolo Aug 13, 2022
8190ac8
Fix merge failure.
futursolo Aug 13, 2022
8160057
Remove LocalRuntime.
futursolo Aug 13, 2022
1d7ea13
Update documentation.
futursolo Aug 13, 2022
e117d3f
Merge branch 'master' into local-runtime
futursolo Aug 17, 2022
fa3e4f6
Merge local-runtime-handle into local-runtime.
futursolo Aug 21, 2022
2523651
Add some tests.
futursolo Aug 21, 2022
d4b4362
Fix clippy notice.
futursolo Aug 21, 2022
9453ba7
Fix comment.
futursolo Aug 21, 2022
a64b080
Address various review comments.
futursolo Aug 28, 2022
a262df3
Remove unused type.
futursolo Aug 28, 2022
09d8a43
Fix clippy.
futursolo Aug 28, 2022
6cd8c64
Fix clippy.
futursolo Aug 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/benchmark-ssr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: Benchmark - SSR

on:
pull_request:
branches: [master]
paths:
- .github/workflows/benchmark-ssr.yml
- "packages/yew"
- "examples/function_router"
- "tools/benchmark-ssr"

jobs:
benchmark-ssr:
name: Benchmark - SSR
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: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
profile: minimal

- name: Restore Rust cache for master
uses: Swatinem/rust-cache@v1
with:
working-directory: yew-master
key: master

- name: Restore Rust cache for current pull request
uses: Swatinem/rust-cache@v1
with:
working-directory: current-pr
key: pr

- name: Build master examples
run: cargo run --profile=bench --bin benchmark-ssr -- --output-path ./output.json
working-directory: yew-master

- name: Build pull request examples
run: cargo run --profile=bench --bin benchmark-ssr -- --output-path ./output.json
working-directory: current-pr

- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: benchmark-ssr
path: |
yew-master/output.json
current-pr/output.json
retention-days: 1
74 changes: 74 additions & 0 deletions .github/workflows/post-benchmark-ssr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
name: Post Comment for Benchmark - SSR

on:
workflow_run:
workflows: ["Benchmark - SSR"]
types:
- completed

jobs:
post-benchmark-ssr:
name: Post Comment on Pull Request
runs-on: ubuntu-latest

steps:
- name: Download Repository
uses: actions/checkout@v2

- if: github.event.workflow_run.event == 'pull_request'
name: Download Artifact
uses: Legit-Labs/action-download-artifact@v2
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
workflow: benchmark-ssr.yml
run_id: ${{ github.event.workflow_run.id }}
name: benchmark-ssr
path: "benchmark-ssr/"

- name: Make pull request comment
run: python3 ci/make_benchmark_ssr_cmt.py

- name: Post Comment
uses: actions/github-script@v6
with:
script: |
const commentInfo = {
...context.repo,
issue_number: ${{ env.PR_NUMBER }},
};

const comment = {
...commentInfo,
body: JSON.parse(process.env.YEW_BENCH_SSR),
};

function isCommentByBot(comment) {
return comment.user.type === "Bot" && comment.body.includes("### Benchmark - SSR");
}

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);
}
2 changes: 1 addition & 1 deletion .github/workflows/post-size-cmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- completed

jobs:
size-cmp:
post-size-cmp:
name: Post Comment on Pull Request
runs-on: ubuntu-latest

Expand Down
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ members = [
# Tools
"tools/benchmark-struct",
"tools/benchmark-hooks",
"tools/benchmark-ssr",
"tools/changelog",
"tools/process-benchmark-results",
"tools/website-test",
]
resolver = "2"

[profile.bench]
lto = true
codegen-units = 1
panic = "abort"
opt-level = 3
56 changes: 56 additions & 0 deletions ci/make_benchmark_ssr_cmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from typing import Dict, List, Optional, Tuple

import os
import json


header = "| Benchmark | Round | Min (ms) | Max (ms) | Mean (ms) | Standard Deviation |"
sep = "| --- | --- | --- | --- | --- | --- |"


def write_benchmark(lines: List[str], content: List[Dict[str, str]]) -> None:
lines.append("<details>")
lines.append("")
lines.append(header)
lines.append(sep)

for i in content:
lines.append(
"| {i.name} | {i.round} | {i.min} | {i.max} | {i.mean} | {i.std_dev} |"
)

lines.append("")
lines.append("</details>")


def main() -> None:
with open("benchmark-ssr/yew-master/output.json") as f:
master_content = json.loads(f.read())

with open("benchmark-ssr/current-pr/output.json") as f:
pr_content = json.loads(f.read())

lines: List[str] = []

lines.append("### Benchmark - SSR")
lines.append("")

lines.append("#### Yew Master")
lines.append("")

write_benchmark(lines, master_content)

lines.append("#### Pull Request")
lines.append("")

write_benchmark(lines, pr_content)

output = "\n".join(lines)

with open(os.environ["GITHUB_ENV"], "a+") as f:
f.write(f"YEW_BENCH_SSR={json.dumps(output)}\n")
f.write(f"PR_NUMBER={issue_number}\n")


if __name__ == "__main__":
main()
6 changes: 3 additions & 3 deletions packages/yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ rust-version = "1.60.0"

[dependencies]
console_error_panic_hook = "0.1"
gloo = "0.8"
gloo = { version = "0.8", features = ["futures"] }
gloo-utils = "0.1.0"
indexmap = { version = "1", features = ["std"] }
js-sys = "0.3"
slab = "0.4"
wasm-bindgen = "0.2"
yew-macro = { version = "^0.19.0", path = "../yew-macro" }
thiserror = "1.0"
futures = { version = "0.3", optional = true }
futures = "0.3"
html-escape = { version = "0.2.9", optional = true }
implicit-clone = { version = "0.3", features = ["map"] }
base64ct = { version = "1.5.0", features = ["std"], optional = true }
Expand Down Expand Up @@ -96,7 +96,7 @@ features = [

[features]
tokio = ["tokio/rt", "dep:num_cpus", "dep:tokio-util"]
ssr = ["dep:futures", "dep:html-escape", "dep:base64ct", "dep:bincode"]
ssr = ["dep:html-escape", "dep:base64ct", "dep:bincode"]
csr = []
hydration = ["csr", "dep:bincode"]
nightly = ["yew-macro/nightly"]
Expand Down
19 changes: 16 additions & 3 deletions packages/yew/src/platform/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pub(crate) fn buffer(capacity: usize) -> (BufWriter, impl Stream<Item = String>)
let (tx, rx) = mpsc::unbounded_channel::<String>();

let tx = BufWriter {
buf: String::with_capacity(capacity),
// We start without allocation so empty strings will not be allocated.
buf: String::new(),
tx,
capacity,
};
Expand Down Expand Up @@ -59,9 +60,18 @@ impl BufWriter {
self.capacity
}

#[inline]
fn drain(&mut self) {
let _ = self.tx.send(self.buf.drain(..).collect());
self.buf.reserve(self.capacity);
if !self.buf.is_empty() {
let _ = self.tx.send(self.buf.split_off(0));
}
}

#[inline]
fn reserve(&mut self) {
if self.buf.is_empty() {
self.buf.reserve(self.capacity);
}
}

/// Returns `True` if the internal buffer has capacity to fit a string of certain length.
Expand All @@ -72,6 +82,9 @@ impl BufWriter {

/// Writes a string into the buffer, optionally drains the buffer.
pub fn write(&mut self, s: Cow<'_, str>) {
// Try to reserve the capacity first.
self.reserve();

if !self.has_capacity_of(s.len()) {
// There isn't enough capacity, we drain the buffer.
self.drain();
Expand Down
Loading