Optimization in use_reducer#3945
Merged
Madoshakalaka merged 5 commits intoyewstack:masterfrom Feb 28, 2026
Merged
Conversation
|
Visit the preview URL for this PR (updated for commit b8538ba): https://yew-rs-api--pr3945-use-reducer-optimiza-z0yvauva.web.app (expires Sat, 07 Mar 2026 03:09:16 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - coreYew MasterPull Request |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
Size ComparisonDetails
✅ None of the examples has changed their size significantly. |
WorldSEnder
reviewed
Nov 16, 2025
5e3dadf to
b8538ba
Compare
Member
|
rebased onto master since it's a breaking change, will probally release with yew 0.23 |
Madoshakalaka
approved these changes
Feb 28, 2026
Member
|
I looked at the SSR benchmarks and It does show a massive performance gain above (~39,000ms → ~32,700ms (20% faster) ) I think it's a solid improvement |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Yew currently provides two versions of the reducer hook:
use_reducer: This hook always causes a re-render when an action is dispatched.use_reducer_eq: This hook avoids the re-render if the new state is the same as the old state. However, the state now has to implementPartialEq.I feel like there is room for a middle ground: The reducer takes an
Rcand returns anRc. Even if we don't have aPartialEqimplementation on the state, we can still know that the state must be unchanged if the reducer returns the exact sameRcback to us. This check is almost free (just a pointer comparison).This PR adds a simple check if the two
Rcs are the same, and in that case skip the re-render.Note that even for
use_reducer_eqthis check is beneficial, since thePartialEqimplementation might be more expensive than just a pointer comparison.This change might be a breaking change if someone was relying on the exact number of re-renders, but I'd assume that this is not covered in Yew's semver guarantees, right?
Checklist