-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
optimized reserve call for memory allocation in advance #15479
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Where did you come up with the 100 chars per expression heuristic? Also, you're not using
shrink_to_fit()
before returning the command, so you're most likely returning a much larger command string than you should be.@blishko I'd be inclined towards closing this is a mostly unnecessary optimization, but it's up to you.
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.
I agree that this is unnecessary optimisation, with a magic number involved.
If anything,
command
should be astringstream
. That would also achieve the desired result in a clearer way.But this is definitely not any bottleneck, AFAIK.
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.
Caching of
vector
'ssize()
is unnecessary as well. It's guaranteed O(1) and introducing an extra local variable for something so trivial is a hit to readability (it's another name you have to keep track of in your head when reading the code) so not a good trade-off.I'd not be against us using things like
reserve()
more in places where the size is non-trivial and known ahead of time, but TBH most of the time the impact is probably insignificant so it does not matter all that much in the big picture. Just changing it randomly in a single spot that is not a known bottleneck is pointless.