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

Attributes: Fix apply_diff_index_maps #2653

Merged
merged 2 commits into from May 5, 2022

Conversation

maurerdietmar
Copy link
Contributor

The old algorithm simply stops when key name/order changes, which is simply wrong.

@WorldSEnder
Copy link
Member

Thanks for the PR. This seems to be present already in the initial implementation in #1537. It being IndexMap means that iteration order is defined by insertion order. I'd guess that has something to do with the bug lying undetected for some time.

Can you add test cases for the behaviour so that it doesn't pop up again later? Ask if you're not sure where and how to write those. Starting with the layout tests in dom_bundle/btag/mod.rs would be an option.

@WorldSEnder WorldSEnder added the A-yew Area: The main yew crate label May 3, 2022
@maurerdietmar
Copy link
Contributor Author

Thanks for the PR. This seems to be present already in the initial implementation in #1537. It being IndexMap means that iteration order is defined by insertion order. I'd guess that has something to do with the bug lying undetected for some time.

Can you add test cases for the behaviour so that it doesn't pop up again later? Ask if you're not sure where and how to write those. Starting with the layout tests in dom_bundle/btag/mod.rs would be an option.

How do I run those test? I get:

# cargo make test
[cargo-make] INFO - cargo make 0.35.11
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: test
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: workspace
/root/rust/yew-fork
[cargo-make][1] INFO - Project: yew
[cargo-make][1] INFO - Build File: Makefile.toml
[cargo-make][1] INFO - Task: test
[cargo-make][1] INFO - Profile: development
[cargo-make][1] INFO - Execute Command: "cargo" "test" "--features" "csr,ssr,hydration"
   Compiling yew v0.19.3 (/root/rust/yew-fork/packages/yew)
error[E0432]: unresolved import `yew::suspense::use_future`
  --> packages/yew/tests/hydration.rs:15:21
   |
15 | use yew::suspense::{use_future, Suspension, SuspensionResult};
   |                     ^^^^^^^^^^ no `use_future` in `suspense`


@futursolo
Copy link
Member

How do I run those test? I get:

That test is missing a feature gate. You can add the following to the beginning of the file:

#![cfg(target_arch = "wasm32")]

@WorldSEnder
Copy link
Member

WorldSEnder commented May 3, 2022

The tests are run from the top-level folder with cargo make tests <-- plural

@maurerdietmar
Copy link
Contributor Author

The tests are run from the top-level folder with cargo make tests <-- plural

cargo make tests

[cargo-make] INFO - cargo make 0.35.11
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: tests
[cargo-make] INFO - Profile: development
[cargo-make] ERROR - Task tests not found
[cargo-make] WARN - Build Failed.

@WorldSEnder
Copy link
Member

WorldSEnder commented May 3, 2022

The tests are run from the top-level folder with cargo make tests <-- plural

cargo make tests

[cargo-make] INFO - cargo make 0.35.11 [cargo-make] INFO - Build File: Makefile.toml [cargo-make] INFO - Task: tests [cargo-make] INFO - Profile: development [cargo-make] ERROR - Task tests not found [cargo-make] WARN - Build Failed.

Oops, I had a version pre-#2640 checked out. You are right... I'll mentally add it to the pile related to #2641 and #2541 and the workaround by futursolo should deal for now ... (also need to add the workaround to hydration.rs, sorry for the bother)

@maurerdietmar
Copy link
Contributor Author

How do I run those test? I get:

That test is missing a feature gate. You can add the following to the beginning of the file:

#![cfg(target_arch = "wasm32")]

OK, that fixes the bug.

Do you know how I cam run a single test? (make test always run all tests)

@WorldSEnder
Copy link
Member

WorldSEnder commented May 3, 2022

How do I run those test? I get:

That test is missing a feature gate. You can add the following to the beginning of the file:
#![cfg(target_arch = "wasm32")]

OK, that fixes the bug.

Do you know how I cam run a single test? (make test always run all tests)

You can go into packages/yew/Makefile.toml and temporarily apply (for native-test and wasm-test separately)

--- a/packages/yew/Makefile.toml
+++ b/packages/yew/Makefile.toml
@@ -1,6 +1,6 @@
 [tasks.native-test]
 command = "cargo"
-args = ["test", "--features", "csr,ssr,hydration"]
+args = ["test", "--features", "csr,ssr,hydration", "--", <your test filter>]
@@ -10,7 +10,9 @@ args = [
     "--headless",
     "--",
     "--features",
-    "wasm_test"
+    "wasm_test",
+    "--",
+    <your test filter, e.g. "index_maps">,
 ]

@maurerdietmar
Copy link
Contributor Author

maurerdietmar commented May 3, 2022

Finally managed to create a test case ...

maurerdietmar added a commit to maurerdietmar/yew that referenced this pull request May 4, 2022
@github-actions
Copy link

github-actions bot commented May 4, 2022

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

https://yew-rs-api--pr2653-fix-apply-diff-index-cq4lwish.web.app

(expires Wed, 11 May 2022 17:35:34 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented May 4, 2022

Size Comparison

examples master (KB) pull request (KB) diff (KB) diff (%)
boids 173.062 172.600 -0.462 -0.267%
contexts 110.644 110.260 -0.384 -0.347%
counter 86.920 86.458 -0.462 -0.531%
counter_functional 87.572 87.110 -0.462 -0.527%
dyn_create_destroy_apps 90.066 89.604 -0.462 -0.513%
file_upload 102.887 102.425 -0.462 -0.449%
function_memory_game 167.609 167.157 -0.452 -0.270%
function_router 350.646 350.262 -0.384 -0.109%
function_todomvc 162.228 161.775 -0.452 -0.279%
futures 226.463 225.938 -0.525 -0.232%
game_of_life 107.747 107.295 -0.452 -0.420%
inner_html 83.957 83.495 -0.462 -0.550%
js_callback 113.063 112.680 -0.384 -0.339%
keyed_list 195.296 194.834 -0.462 -0.237%
mount_point 86.546 86.084 -0.462 -0.534%
nested_list 116.081 115.697 -0.384 -0.331%
node_refs 90.718 90.256 -0.462 -0.509%
password_strength 1538.550 1538.088 -0.462 -0.030%
portals 97.382 96.998 -0.384 -0.394%
router 316.220 315.836 -0.384 -0.121%
simple_ssr 494.152 493.695 -0.457 -0.092%
ssr_router 426.188 425.731 -0.457 -0.107%
suspense 110.765 110.376 -0.389 -0.351%
timer 89.658 89.196 -0.462 -0.515%
todomvc 143.289 142.837 -0.452 -0.316%
two_apps 87.554 87.092 -0.462 -0.528%
web_worker_fib 153.592 153.130 -0.462 -0.301%
webgl 87.638 87.176 -0.462 -0.527%

✅ None of the examples has changed their size significantly.

maurerdietmar added a commit to maurerdietmar/yew that referenced this pull request May 4, 2022
WorldSEnder
WorldSEnder previously approved these changes May 4, 2022
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.

Performance alert is a false positive, as far as I can tell.

@futursolo
Copy link
Member

@maurerdietmar Could you please rebase / merge from master so size comparison test can run?

The old algorithm simply stops when key name/order changes, which
is simply wrong.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
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.

Arguably, both the new and old attribute set often have <10 entries, so all those iterations are preferable to keeping extra state to track leftover attributes to remove (changing the signature slightly, alternatively old can potentially be mutable). We can try it in a follow-up but the fix itself looks good. Thanks for the test case.

@futursolo futursolo merged commit e588013 into yewstack:master May 5, 2022
@maurerdietmar maurerdietmar deleted the fix-apply-diff-index-maps branch May 5, 2022 10:32
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants