-
-
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
Improve speed of to_string for Classes #772
Conversation
self.set | ||
.iter() | ||
.map(String::as_str) | ||
.collect::<Vec<&str>>() |
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.
@hgzimmerman could you please add benchmark results to PRs with perf changes like this?
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.
How do you suggest that they be integrated into the project?
This one would be easy enough to copy relevant code into a separate project, run the benchmark and throw the project away when done.
Or instead should a benchmarks directory (analogous to tests or examples) be created?
Or finally, just leave a benchmark as part of a tests or benchmarks module within the existing file?
While I await your response, I'll pursue the first option.
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.
Yeah I was suggesting running benchmarks locally and pasting the results (ideally in the PR description). I'll add a formal process for this soon
Benchmarks are ran using the nightly Tests were ran against sets of 1, 2, 5, and 10 classes as more are unlikely to be used under typical use cases. Results
AnalysisThe proposed change is within the margin of error in the 1 class case, while meaningfully faster for inputs larger than 1. |
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.
Thanks for adding the benchmark results!
The prior code would reallocate for every item in the set that is pushed into the buffer. This should make one bigger allocation for the
Vec<&str>
(assuming it uses the size_hint? - worst case it makes a log_n number of allocations to accommodate the str references) and another for joining it into the finalString
with spaces.