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.
Change set 1:
I had intended to make the function
mc::mc_add_vertex
branchless to improve performance but it was not more performant on quickbench. I then added "-ffast-math" and saw the performance decrease even more so there may be a flaw in my benchmark.For documentation the code was:
And was later changed to use ternary operators instead of floating point maths.
Change set 2:
These changes relate to reserving the size of vectors before adding to them.
By default vectors have a small capacity, the standard does not specify but (cppreference)[https://en.cppreference.com/w/cpp/container/vector/capacity] suggests they start at 0. When an item would be added past the end of the buffer the internal buffer goes through a reallocation. Normally this reallocation adds half the size of the buffer again, (growing by 1.5x).
Reserving an initial estimate with
.reserve()
will heavily reduce the amount of allocations and increase the speed of the program. Overusing reserve (say reserving 3 inmc_add_vertex
) can increase the amount of allocations, worsening performance.Much better estimates may further increase performance.