Make `Key` avoid an allocation, make it faster to compare than Strings
voidpumpkin opened this issue · comments
Make Key
avoid an allocation, make it faster to compare than Strings.
Original discussion: #2804
Just want to mention the previous suggestion: Simply use IString for key.
From what I see:
1.) There is no allocation necessary for static strings, which is the most common case?
2.) Compare is already quite fast (Rc::ptr_eq)
1.) There is no allocation necessary for static strings, which is the most common case?
2.) Compare is already quite fast (Rc::ptr_eq)
I think it's more common for keys to be used to render data fetched from a server and id's returned in the data structure will be used as keys as static data can pre-define html!
and avoid keys.
When data is fetched from a server the keys are not static and types need to be casted into Key on every render.
The main reason why an allocation-less is more desirable is due to that an allocation can be avoided completely if the key is originally an allocation-less type.
This also solves some weird issues with the current Key implementation.
e.g.: assert_eq!(Key::from("0"), Key::from(0_u64));
You can read the full conversation here: #2616
(Although the PR didn't go through due to significant binary size increase.)