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

Add WASI support for server-side rendering. #3534

Merged
merged 95 commits into from
Oct 21, 2024

Conversation

langyo
Copy link
Contributor

@langyo langyo commented Nov 21, 2023

Description

I've been trying to use yew to render the page into the static HTML string on WASI. However, yew cannot distinguish the browser WASM target (wasm32-unknown-unknown with wasm-bindgen) and WASI target (wasm32-wasi), and it would choose wrong modules for wasm32-*.

In addition, since the current SSR implementation will create new tasks directly in the asynchronous context directly (based on prokio). It only allowed in a multi-threaded environment that it is not compatible with WASI. So I added a dedicated one for a single-threaded environment that rendering function to support single-threaded scenes.

To support this new feature, I have also made changes along with some other upstream dependencies. I've created some PRs for these upstream dependencies, and added a temporary patch entry to the root Cargo.toml for this PR. If the upstream branch can be processed, these temporary patch entries could be replaced.

I also wrote a short example for this new feature.

CC @futursolo 😉

Checklist

  • I have reviewed my own code
  • I have added tests

Copy link

github-actions bot commented Nov 21, 2023

Benchmark - core

Yew Master

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.968 ns      │ 3.041 ns      │ 2.988 ns      │ 2.989 ns      │ 100     │ 1000000000

Pull Request

vnode           fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ vnode_clone  2.986 ns      │ 3.096 ns      │ 2.993 ns      │ 2.995 ns      │ 100     │ 1000000000

Copy link

github-actions bot commented Nov 21, 2023

Visit the preview URL for this PR (updated for commit 4a3b79f):

https://yew-rs--pr3534-wasi-support-test-8w8rolp5.web.app

(expires Mon, 02 Sep 2024 02:55:49 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Copy link

github-actions bot commented Nov 21, 2023

Benchmark - SSR

Yew Master

Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 289.303 289.917 289.487 0.244
Hello World 10 495.218 502.854 498.844 3.225
Function Router 10 1655.731 1690.352 1672.628 12.751
Concurrent Task 10 1005.178 1006.620 1005.978 0.494
Many Providers 10 1122.085 1162.368 1138.665 13.104

Pull Request

Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 289.249 289.463 289.345 0.073
Hello World 10 515.033 518.411 516.701 1.213
Function Router 10 1614.825 1653.319 1623.054 11.098
Concurrent Task 10 1004.953 1006.618 1005.731 0.469
Many Providers 10 1183.398 1218.504 1193.656 12.951

Copy link

github-actions bot commented Nov 21, 2023

Size Comparison

examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 96.327 96.327 0 0.000%
boids 168.066 168.066 0 0.000%
communication_child_to_parent 89.818 89.818 0 0.000%
communication_grandchild_with_grandparent 101.845 101.845 0 0.000%
communication_grandparent_to_grandchild 97.510 97.510 0 0.000%
communication_parent_to_child 86.358 86.358 0 0.000%
contexts 101.714 101.714 0 0.000%
counter 82.761 82.761 0 0.000%
counter_functional 83.209 83.209 0 0.000%
dyn_create_destroy_apps 85.966 85.966 0 0.000%
file_upload 95.986 95.986 0 0.000%
function_memory_game 167.535 167.535 0 0.000%
function_router 333.431 333.411 -0.020 -0.006%
function_todomvc 160.954 160.954 0 0.000%
futures 234.979 234.979 0 0.000%
game_of_life 104.846 104.846 0 0.000%
immutable 185.640 185.640 0 0.000%
inner_html 77.420 77.420 0 0.000%
js_callback 104.540 104.540 0 0.000%
keyed_list 195.628 195.628 0 0.000%
mount_point 80.155 80.155 0 0.000%
nested_list 109.956 109.956 0 0.000%
node_refs 87.709 87.709 0 0.000%
password_strength 1777.415 1777.415 0 0.000%
portals 90.337 90.337 0 0.000%
router 304.342 304.325 -0.017 -0.005%
simple_ssr 137.193 137.193 0 0.000%
ssr_router 370.538 370.515 -0.023 -0.006%
suspense 108.910 108.910 0 0.000%
timer 85.505 85.505 0 0.000%
timer_functional 93.200 93.200 0 0.000%
todomvc 141.917 141.917 0 0.000%
two_apps 82.834 82.834 0 0.000%
web_worker_fib 131.337 131.337 0 0.000%
web_worker_prime 182.851 182.851 0 0.000%
webgl 80.139 80.139 0 0.000%

✅ None of the examples has changed their size significantly.

ranile
ranile previously approved these changes Oct 10, 2024
Copy link
Member

@ranile ranile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for your patience. My apologies for how long it took to review

@ranile
Copy link
Member

ranile commented Oct 12, 2024

@WorldSEnder this is pending your review. If you're unable to review, I'll dismiss the previous (now-resolved) review and get this merged

@ranile
Copy link
Member

ranile commented Oct 12, 2024

@langyo can you please undo the formatting changes your editor did in the meantime? I'll merge this PR on Monday if @WorldSEnder doesn't respond by then

@langyo langyo force-pushed the wasi-support-test branch 3 times, most recently from 8d07370 to 6155846 Compare October 12, 2024 16:54
@ranile ranile dismissed WorldSEnder’s stale review October 16, 2024 12:22

Review already addressed, need to dismiss to merge PR

@ranile ranile merged commit 84b7548 into yewstack:master Oct 21, 2024
26 checks passed
@ranile
Copy link
Member

ranile commented Oct 21, 2024

Merging this (finally!). Any changes needed can come in further PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants