Skip to content

Commit

Permalink
Preventing resize overuse in SortVisibleSpans
Browse files Browse the repository at this point in the history
Adding an if check to resize the buffers only when there is a risk of an overflow.

Every pass through is resizing the scratch buffers in SortVisibleSpans. Resize is completely deallocating and reallocating the buffers. This is resulting in a ~5% performance drag - so this change results in a ~5% performance improvement on the main loop.

It’s possible this is a result of 78c0b48 which moved this storage over to std. I don’t know if the Cyan array implementation would have handled this.

I don’t see any reason this would create issues - there doesn’t seem to be code that relies on the size of the vectors. The vectors only need to be correctly sized to fit all the data required.
  • Loading branch information
colincornaby committed Dec 30, 2024
1 parent 76e31fe commit 071bdc1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,8 +1783,11 @@ void plDrawableSpans::SortVisibleSpans(const std::vector<int16_t>& visList, plPi

plProfile_IncCount(FacesSorted, totTris);

sortScratch.resize(totTris);
triList.resize(3 * totTris);
if( sortScratch.size() < totTris )
{
sortScratch.resize(totTris);
triList.resize(3 * totTris);
}

hsRadixSort::Elem* elem = sortScratch.data();

Expand Down

0 comments on commit 071bdc1

Please sign in to comment.