yew icon indicating copy to clipboard operation
yew copied to clipboard

Make `Key` avoid an allocation, make it faster to compare than Strings

Open voidpumpkin opened this issue 2 years ago • 2 comments

Make Key avoid an allocation, make it faster to compare than Strings.

Original discussion: #2804

voidpumpkin avatar Apr 02 '23 12:04 voidpumpkin

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)

maurerdietmar avatar Apr 13 '23 09:04 maurerdietmar

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: https://github.com/yewstack/yew/pull/2616 (Although the PR didn't go through due to significant binary size increase.)

futursolo avatar Apr 22 '23 18:04 futursolo