feat: replace Key internals with DefaultHasher for allocation-free comparison#4006
Conversation
|
Visit the preview URL for this PR (updated for commit 61913af): https://yew-rs-api--pr4006-key-defaulthasher-qyp24pfl.web.app (expires Thu, 05 Mar 2026 08:37:08 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - coreYew MasterPull Request |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
Size ComparisonDetails
|
|
Looks like a pure win, every example shrunk, no performance regression, cleaner semantics. Recall that the original PR #2616 was rejected partly due to binary size increases of 1-8 KB. We all good here. |
…mparison (#3205) BREAKING CHANGE: Key no longer implements Deref<Target=str>. BREAKING CHANGE: Keys from different types with the same string representation are no longer equal (e.g. Key::from("0") != Key::from(0u64)). BREAKING CHANGE: Display in release mode shows #<hash> instead of the original value.
4cea59b to
61913af
Compare
|
Is there any protection against runtime collisions (in release mode)? This seems exactly as if saying to each user to find a way to map uniquely to an u64 and saying that hash collisions are a user error. I find this less convincing than I did 3 years ago. There is a reason a hashmap does a key comparison when it finds a matching hash and doesn't just assume. There must be other ways to avoid the conversion from a String allocation to an Rc allocation and judging only on metrics seems misguided: this removes functionality. We might as well allow only u64 as key input now. |
No. I just trusted the consensus in the original discussion and regarded the low collision rate as acceptible. I'll fix this in a later PR then. |
Description
Replaces Key's internal Rc with a NonZeroU64 hash computed via DefaultHasher, as discussed in #3205 and the earlier PR #2616.
closes #3205
Checklist