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

Experiment with a structless variant of Yew #2957

Closed
wants to merge 48 commits into from

Conversation

futursolo
Copy link
Member

@futursolo futursolo commented Nov 9, 2022

Description

#2282 discusses the possibility of removing struct components. There are opinions that are both in favour of removing struct components and keeping them. However, there was no proof of concept that demonstrates what would be possible if function component becomes the only supported component type.

This pull request provides a prototype for #2282.
I do not expect this pull request to be merged, this is purely for demonstration purpose.

Currently I have only verified the function_router example and benchmark_ssr works.

A short summary:

1. Lifecycles are no longer boxed

This removes many allocations.
Lifecycle events are now pure function calls and commits immediately regardless of whether being an element or component. Previously, components commit at a later lifecycle events because we need to make sure parent state is not borrowed, function components do not have this requirement.
Hence, many workarounds currently used by hydration (priority rendering, etc.) can be removed.

This is possible because the lifecycle events are much simpler for function components and they do not need to mutably borrow any parent state.

2. Many boxed types and generics are removed

Mounting a component now involves 1 allocation (Rc<ScopeInner>).
Re-render does not involve any allocations (after Html is created.).

The function_router example is now ~40KB smaller.

3. SSR no longer needs to run any lifecycle events.

The hello world SSR benchmark is 100% faster than master branch.

4. Component states are no longer maintained via reference cycles.

Checklist

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

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

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

https://yew-rs-api--pr2957-structless-o27nw8px.web.app

(expires Fri, 18 Nov 2022 04:52:04 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Size Comparison

examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 108.628 N/A N/A N/A
boids 172.869 N/A N/A N/A
communication_child_to_parent 92.510 N/A N/A N/A
communication_grandchild_with_grandparent 107.214 N/A N/A N/A
communication_grandparent_to_grandchild 103.091 N/A N/A N/A
communication_parent_to_child 89.613 N/A N/A N/A
contexts 109.892 N/A N/A N/A
counter 87.522 N/A N/A N/A
counter_functional 88.000 81.056 -6.944 -7.891%
dyn_create_destroy_apps 90.384 N/A N/A N/A
file_upload 102.066 N/A N/A N/A
function_memory_game 165.372 145.061 -20.312 -12.282%
function_router 349.626 306.534 -43.092 -12.325%
function_todomvc 160.147 143.255 -16.893 -10.548%
futures 224.212 N/A N/A N/A
game_of_life 107.047 N/A N/A N/A
immutable 184.616 N/A N/A N/A
inner_html 84.129 N/A N/A N/A
js_callback 113.431 103.745 -9.686 -8.539%
keyed_list 198.051 N/A N/A N/A
mount_point 87.132 N/A N/A N/A
nested_list 114.165 N/A N/A N/A
node_refs 95.006 N/A N/A N/A
password_strength 1549.240 N/A N/A N/A
portals 98.516 N/A N/A N/A
router 319.420 N/A N/A N/A
simple_ssr 154.111 142.482 -11.629 -7.546%
ssr_router 394.614 342.947 -51.667 -13.093%
suspense 111.245 101.676 -9.569 -8.602%
timer 90.408 N/A N/A N/A
todomvc 141.444 N/A N/A N/A
two_apps 88.192 N/A N/A N/A
web_worker_fib 154.501 N/A N/A N/A
webgl 86.819 N/A N/A N/A

⚠️ The following examples have changed their size significantly:

examples master (KB) pull request (KB) diff (KB) diff (%)
counter_functional 88.000 81.056 -6.944 -7.891%
function_memory_game 165.372 145.061 -20.312 -12.282%
function_router 349.626 306.534 -43.092 -12.325%
function_todomvc 160.147 143.255 -16.893 -10.548%
js_callback 113.431 103.745 -9.686 -8.539%
simple_ssr 154.111 142.482 -11.629 -7.546%
ssr_router 394.614 342.947 -51.667 -13.093%
suspense 111.245 101.676 -9.569 -8.602%

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Benchmark - SSR

Yew Master

Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 338.514 366.697 345.306 10.115
Hello World 10 637.161 643.690 639.028 2.126
Function Router 10 2240.224 2258.750 2245.693 5.697
Concurrent Task 10 1007.731 1009.692 1009.036 0.571

Pull Request

Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 336.656 342.566 338.212 1.822
Hello World 10 293.208 297.767 294.923 1.527
Function Router 10 1766.444 1824.582 1782.136 18.528
Concurrent Task 10 1007.561 1008.882 1008.248 0.418

flaviu-toader pushed a commit to flaviu-toader/yew that referenced this pull request Nov 11, 2022
…oved (yewstack#2629)

* Separate hydration and render queue.

* Revert "Fix issue with node refs and hydration (yewstack#2597)"

This reverts commit 469cc34.

* Priority Render.

* Add some tests.

* Add more tests.

* Add test result after click.

* Fix test comment.

* Fix test timing.

* Restore test.

* Once AtomicBool, now a Cell.

* Prefer use_future.

* Revealing of Suspense always happen after the component has re-rendered itself.

* Shifting should register correct next_sibling.

* Revert to HashMap.

* cargo +nightly fmt.

* Fix comment.

* Optimise Code size?

* Add comment if assertion fails.

* Revert "Merge branch 'hydration-4' into fc-prepared-state"

This reverts commit 427b087d4db6b2e497ad618273655bd18ba9bd01, reversing
changes made to 109fcfa.

* Revert "Revert "Merge branch 'hydration-4' into fc-prepared-state""

This reverts commit f1e4089.

* Redo yewstack#2957.
@futursolo futursolo closed this Nov 13, 2022
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.

1 participant