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

Remove component NodeRef #2783

Merged
merged 8 commits into from Jul 20, 2022
Merged

Conversation

hamza1311
Copy link
Member

@hamza1311 hamza1311 commented Jul 19, 2022

Description

Fixes #2505

This is half of #2551/#2567. This PR removes the NodeRef for components. We can add ComponentRef in the future.

cc: @WorldSEnder @futursolo

Checklist

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

@hamza1311 hamza1311 added A-yew Area: The main yew crate breaking change labels Jul 19, 2022
github-actions[bot]
github-actions bot previously approved these changes Jul 19, 2022
@hamza1311 hamza1311 changed the title #### Description Remove component NodeRef Remove component NodeRef Jul 19, 2022
this test is done at compile time. there's no node_ref field so it can't be set
github-actions[bot]
github-actions bot previously approved these changes Jul 19, 2022
@github-actions
Copy link

github-actions bot commented Jul 19, 2022

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

https://yew-rs--pr2783-begone-comp-node-ref-vybofh7a.web.app

(expires Wed, 27 Jul 2022 16:32:26 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented Jul 19, 2022

Size Comparison

examples master (KB) pull request (KB) diff (KB) diff (%)
boids 173.431 173.237 -0.193 -0.111%
contexts 110.138 109.829 -0.309 -0.280%
counter 87.038 86.772 -0.266 -0.305%
counter_functional 87.701 87.438 -0.263 -0.300%
dyn_create_destroy_apps 90.149 89.912 -0.237 -0.263%
file_upload 103.500 103.239 -0.261 -0.252%
function_memory_game 168.630 168.312 -0.318 -0.189%
function_router 353.755 353.087 -0.668 -0.189%
function_todomvc 162.418 162.134 -0.284 -0.175%
futures 226.104 225.839 -0.265 -0.117%
game_of_life 107.697 107.433 -0.265 -0.246%
immutable 210.053 209.761 -0.292 -0.139%
inner_html 84.057 83.792 -0.265 -0.315%
js_callback 113.381 113.033 -0.348 -0.307%
keyed_list 195.875 195.649 -0.226 -0.115%
mount_point 86.680 86.418 -0.262 -0.302%
nested_list 116.255 115.924 -0.331 -0.285%
node_refs 93.980 93.680 -0.301 -0.320%
password_strength 1547.374 1547.103 -0.271 -0.018%
portals 97.867 97.561 -0.307 -0.313%
router 321.681 321.417 -0.264 -0.082%
simple_ssr 154.938 154.527 -0.410 -0.265%
ssr_router 400.144 399.222 -0.922 -0.230%
suspense 111.044 110.642 -0.402 -0.362%
timer 89.729 89.467 -0.263 -0.293%
todomvc 143.397 143.126 -0.271 -0.189%
two_apps 87.691 87.429 -0.263 -0.300%
web_worker_fib 154.685 154.430 -0.255 -0.165%
webgl 87.948 87.682 -0.267 -0.303%

✅ None of the examples has changed their size significantly.

#[cfg(feature = "ssr")]
use crate::platform::io::BufWriter;

/// A virtual component.
pub struct VComp {
pub(crate) type_id: TypeId,
pub(crate) mountable: Box<dyn Mountable>,
pub(crate) node_ref: NodeRef,
Copy link
Member

Choose a reason for hiding this comment

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

I don't know why is this the case, but the bundle size increase is likely due to the removal of this field.

Copy link
Member Author

@hamza1311 hamza1311 Jul 19, 2022

Choose a reason for hiding this comment

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

Removing a field causing increase in bundle size... That doesn't really make sense to me

Do you know why it might be causing that?

Copy link
Member

@futursolo futursolo Jul 19, 2022

Choose a reason for hiding this comment

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

I think this has something to do with the size of the struct, you can try to replace it with _marker: usize and set the value to 0 in the constructor. This should also work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I ran twiggy and it seems like most of bytes are coming from code that is untouched here:

yew/examples/counter_functional [begone-comp-node-ref]〉twiggy diff dist/counter_functional-931e7c89893382d7_bg.wasm dist-pr/counter_functional-ad2bf05e16727653_bg.wasm -n 10
 Delta Bytes │ Item
─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        +510 ┊ yew::dom_bundle::blist::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vlist::VList>::reconcile::h897bdbe92f15f88d
        -285 ┊ yew::dom_bundle::bcomp::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vcomp::VComp>::attach::hbd2d9621b55add0b
        +253 ┊ <yew::html::component::lifecycle::CompStateInner<COMP> as yew::html::component::lifecycle::Stateful>::view::h68b91f18b2519e4c
        +234 ┊ yew::dom_bundle::bcomp::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vcomp::VComp>::attach::hde8285620aedef9a
        +150 ┊ yew::dom_bundle::bsuspense::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vsuspense::VSuspense>::attach::hb3a4b9fd00446556
        +144 ┊ yew::dom_bundle::bnode::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vnode::VNode>::reconcile_node::h2888f3017cf1b126
        +123 ┊ yew::dom_bundle::blist::BList::apply_unkeyed::hf07a69927390bfbe
         +87 ┊ <core::iter::adapters::zip::Zip<A,B> as core::iter::traits::iterator::Iterator>::next::hf228331121bfac52
         +60 ┊ yew::dom_bundle::bportal::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vportal::VPortal>::attach::h22b2b8a5f486b6e5
         +53 ┊ <yew::html::component::lifecycle::RenderRunner as yew::scheduler::Runnable>::run::h84768ff9205d0ffa
         +23 ┊ ... and 17 more.
       +1352 ┊ Σ [27 Total Rows]

not sure what's happening here

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's weird. But increase the size of this struct does work.

376K with-marker/router/dist/router-872e26b381599680_bg.wasm
384K without-marker/router/dist/router-514df72ff86f280e_bg.wasm

github-actions[bot]
github-actions bot previously approved these changes Jul 19, 2022
github-actions[bot]
github-actions bot previously approved these changes Jul 20, 2022
futursolo
futursolo previously approved these changes Jul 20, 2022
Copy link
Member

@futursolo futursolo left a comment

Choose a reason for hiding this comment

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

I am in favour of merging this and removing ref implementation from v0.20 roadmap.

Other than needs updating the migration guide, LGTM.

@hamza1311 hamza1311 dismissed stale reviews from futursolo and github-actions via a15b5db July 20, 2022 16:21
@hamza1311 hamza1311 requested a review from futursolo July 20, 2022 16:31
@hamza1311 hamza1311 enabled auto-merge (squash) July 20, 2022 16:31
@hamza1311 hamza1311 merged commit 544990a into yewstack:master Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-yew Area: The main yew crate breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Components should not have a node ref
2 participants