-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Various improvements to Classes, oriented around reducing allocations #2870
Conversation
- `push` no longer performs unnecessary allocations if `self` is empty. - Most constructors (FromIterator, From, Extend) are now oriented around push, to take advantage of this - `to_string` and `into_prop_value`: - No longer allocate an unnecessary `Vec`; they instead preallocate a string of the correct length and push into it directly. - No longer use a length check + `unsafe`; they instead match over a fallible .next() and proceed from there. - Additionally, `into_prop_value` no longer builds a `String` or `Rc` if `Classes` contains a single `&'static str` or is empty. - `From<String>` no longer clones the string if it contains a single class. - `impl Eq for Classes`
Note: in the future, as a slightly breaking change, we should consider redoing some of the implementation patterns around |
Visit the preview URL for this PR (updated for commit 2016989): https://yew-rs-api--pr2870-improved-classes-psuc2ffr.web.app (expires Sat, 24 Sep 2022 01:23:58 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - SSRYew Master
Pull Request
|
Size Comparison
✅ None of the examples has changed their size significantly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the pull request. Looks good to me.
Cost of creating 1,000,000 Classes with 5 classes and convert them to a String
:
Round: 1 (Warm up)
&'static str (pull request): 439ms
&'static str (master): 404ms
String (pull request): 673ms
String (master): 679ms
Round: 2
&'static str (pull request): 399ms
&'static str (master): 403ms
String (pull request): 673ms
String (master): 678ms
Round: 3
&'static str (pull request): 397ms
&'static str (master): 401ms
String (pull request): 676ms
String (master): 679ms
Round: 4
&'static str (pull request): 399ms
&'static str (master): 404ms
String (pull request): 669ms
String (master): 674ms
Round: 5
&'static str (pull request): 396ms
&'static str (master): 401ms
String (pull request): 668ms
String (master): 677ms
@futursolo how did you run the benchmarks? Can those be run as part alongside the other benchmarks that we have? |
Description
push
no longer performs unnecessary allocations ifself
is empty. - Most constructors (FromIterator, From, Extend) that were already based aroundInto<Classes>
are now oriented around push, to take advantage of thisto_string
andinto_prop_value
:Vec
; they instead preallocate a string of the correct length and push into it directly.unsafe
; they instead match over a fallible .next() and proceed from there.into_prop_value
no longer builds aString
orRc
ifClasses
contains a single&'static str
or is empty.From<String>
no longer clones the string if it contains a single class.FromIterator<String>
andIterator<&str>.map(to_owned)
impl Eq for Classes
Checklist