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 the ability to use non-literal string as attribute names #2593

Merged
merged 5 commits into from Apr 12, 2022

Conversation

hamza1311
Copy link
Member

Description

Use AttrValue instead of &'static str in Attributes::IndexMap

Fixes #2583

Checklist

  • I have run cargo make pr-flow
  • I have reviewed my own code
  • I have updated tests

@hamza1311 hamza1311 added breaking change A-yew Area: The main yew crate labels Apr 8, 2022
@hamza1311 hamza1311 added this to the v0.20 milestone Apr 8, 2022
github-actions[bot]
github-actions bot previously approved these changes Apr 8, 2022
github-actions[bot]
github-actions bot previously approved these changes Apr 8, 2022
@github-actions
Copy link

github-actions bot commented Apr 8, 2022

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

https://yew-rs-api--pr2593-dynamic-attr-name-fy7rmfls.web.app

(expires Tue, 19 Apr 2022 18:01:01 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented Apr 8, 2022

Size Comparison

examples master (KB) pull request (KB) diff
boids 219.341 218.836 -0.505
contexts 136.297 135.968 -0.329
counter 111.442 111.061 -0.382
counter_functional 112.305 111.923 -0.382
dyn_create_destroy_apps 114.877 114.558 -0.319
file_upload 127.909 127.591 -0.318
function_memory_game 214.932 214.588 -0.344
function_router 406.019 405.774 -0.244
function_todomvc 207.714 207.521 -0.192
futures 270.011 270.006 -0.005
game_of_life 139.760 139.482 -0.277
inner_html 107.222 106.914 -0.308
js_callback 114.629 114.301 -0.328
keyed_list 246.226 245.764 -0.462
mount_point 110.972 110.665 -0.307
nested_list 141.521 141.408 -0.112
node_refs 113.855 113.548 -0.308
password_strength 1618.833 1618.495 -0.338
portals 122.024 121.715 -0.310
router 371.017 370.723 -0.294
simple_ssr 573.411 573.063 -0.348
ssr_router 495.621 495.491 -0.130
suspense 135.374 135.079 -0.295
timer 113.825 113.506 -0.319
todomvc 189.500 189.296 -0.204
two_apps 111.817 111.454 -0.363
webgl 113.504 113.196 -0.308

@WorldSEnder
Copy link
Member

WorldSEnder commented Apr 10, 2022

Can you investigate the hit on bundle-size across the board? Seems unexpected and unintended to me, is the optimizer getting confused?

@hamza1311
Copy link
Member Author

I tried to investigate but I couldn't find anything directly related to this PR. Here's the twiggy output:

$ twiggy diff dist/index-bb8d1efa01b11b21_bg.wasm dist-dynamic-attr-name/index-6f54447ec41e7ed9_bg.wasm 
 Delta Bytes │ Item
─────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       -6253 ┊ yew::dom_bundle::blist::BList::apply_keyed::hf680e9371ffcfa81
       +6210 ┊ yew::dom_bundle::blist::<impl yew::dom_bundle::traits::Reconcilable for yew::virtual_dom::vlist::VList>::reconcile::ha8ea041d17b3fc5c
       +1437 ┊ hashbrown::raw::inner::RawTable<T,A>::reserve_rehash::h40031a0cfbb9e96c
       +1276 ┊ "function names" subsection
       +1271 ┊ yew::dom_bundle::btag::attributes::<impl yew::virtual_dom::Attributes>::apply_diff_index_maps::h181d55d80e5264fc
        -891 ┊ yew::dom_bundle::btag::attributes::<impl yew::virtual_dom::Attributes>::apply_diff_index_maps::h4bfa137a4275df06
        -881 ┊ yew::dom_bundle::btag::attributes::<impl yew::virtual_dom::Attributes>::apply_diff_as_maps::collect::hb3fbac229c6347e3
        +683 ┊ indexmap::map::core::IndexMapCore<K,V>::insert_full::h121fd42eb1f406bf
        -566 ┊ indexmap::map::IndexMap<K,V,S>::get::hda0b66b0256234d1
        +548 ┊ <indexmap::map::IndexMap<K,V,S> as core::iter::traits::collect::FromIterator<(K,V)>>::from_iter::h32c93fc97d4bd63e
        +527 ┊ indexmap::map::IndexMap<K,V,S>::get_index_of::h1bb8bd88c02cee45
        +488 ┊ indexmap::map::IndexMap<K,V,S>::insert::hed62990bad1560ea
        -485 ┊ indexmap::map::IndexMap<K,V,S>::hash::heed10a80940f879e
        +411 ┊ hashbrown::raw::inner::RawTable<T,A>::insert::h3a9a8041e2b2123a
        -395 ┊ <yew::dom_bundle::blist::BList as yew::dom_bundle::traits::ReconcileTarget>::detach::h0b1c0428510f8cda
        +394 ┊ hashbrown::raw::inner::RawTableInner<A>::fallible_with_capacity::h20c0bb40a3676429
        -382 ┊ <yew::html::component::lifecycle::RenderRunner as yew::scheduler::Runnable>::run::h382951aaf4a36be2
        -325 ┊ indexmap::map::core::IndexMapCore<K,V>::get_index_of::h3f5de4587318f981
        +320 ┊ <std::collections::hash::map::HashMap<K,V,S> as core::iter::traits::collect::FromIterator<(K,V)>>::from_iter::hfafdf0197eb883f6
        +316 ┊ <std::collections::hash::map::HashMap<K,V,S> as core::iter::traits::collect::FromIterator<(K,V)>>::from_iter::h6c17f83a723f590c
       +2474 ┊ ... and 50 more.
       +5800 ┊ Σ [70 Total Rows]

If you know of a solution, I would like to hear it.

github-actions[bot]
github-actions bot previously approved these changes Apr 11, 2022
github-actions[bot]
github-actions bot previously approved these changes Apr 11, 2022
@hamza1311
Copy link
Member Author

I tried to reduce the bundle size as much as I could. I don't have any other leads on what I can do to try to reduce the bundle size

github-actions[bot]
github-actions bot previously approved these changes Apr 11, 2022
@WorldSEnder
Copy link
Member

I tried to reduce the bundle size as much as I could. I don't have any other leads on what I can do to try to reduce the bundle size

I'll also have a go at this before adding my review. On a superficial look, lgtm.

Copy link
Member

@WorldSEnder WorldSEnder left a comment

Choose a reason for hiding this comment

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

I think I found a way to keep the size small. Other than that, looks good to me. We might want to revisit the implementation at some point, it seems to collect(), i.e. recreate, IndexMap a few times, which sounds unfortunate for performance.

packages/yew/src/dom_bundle/btag/attributes.rs Outdated Show resolved Hide resolved
packages/yew/src/dom_bundle/btag/attributes.rs Outdated Show resolved Hide resolved
@@ -57,6 +58,7 @@ pub enum AttrValue {
impl Deref for AttrValue {
type Target = str;

#[inline(always)]
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 think theses inline annotations actually effect anything, might as well remove them again.

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 think we should just keep them as they hint the compiler. The stdlib also has them

github-actions[bot]
github-actions bot previously approved these changes Apr 12, 2022
@hamza1311 hamza1311 merged commit e9b64e0 into yewstack:master Apr 12, 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.

Add ability to dynamically create attributes for VTag
2 participants