Optimize LocalVector::push_back
for non-trivial objects
#104693
Merged
+1
−1
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.
I happened to stumble upon this discrepancy between how trivially constructible objects and non-trivially constructible objects were being constructed in
LocalVector::push_back
, where trivially constructible objects seemed to be usingstd::move
(thus avoiding the redundant copy) and non-trivially constructible objects were not.It seemed to be something that was missed as part of #100477, as mentioned by @Ivorforce here.
Some quick for-loop profiling using this code with MSVC...
... yielded 15.48 ms without the change and 12.89 ms with the change, so roughly a 16% reduction for
Variant
specifically, but obviously depends greatly on what the object does in its copy constructor.(This also seems to be the only thing standing in the way of
LocalVector
being able to contain move-only types.)