Performance improvement for fixed_vector
AZStd::fixed_vector had all its functions marked with constexpr, but this requires all member variables to be fully initialized. This meant that the internal array used to store elements always has to be fully initialized. This was done for trivial classes but not for non-trivial classes. As a result trivial classes always did a memset (or more optimized versions for smaller buffers) while the non-trivial version couldn't actually be stored in a constexpr variable. Since AZStd::fixed_vector is meant to be dynamic the choice was made to remove the constexpr from all non-static member functions in favor of avoiding the overhead of memset, which profiling showed was a considerable overhead depending on the reserved size. If a truly constexpr array is needed than AZStd::array is a better choice as that's designed to not by dynamic. Signed-off-by: AMZN-koppersr <82230785+AMZN-koppersr@users.noreply.github.com>
This commit is contained in:
@@ -753,7 +753,7 @@ namespace UnitTest
|
||||
|
||||
TEST_F(Arrays, FixedVectorCanCopyAndMoveWithDifferentCapacity)
|
||||
{
|
||||
constexpr AZStd::fixed_vector<int, 32> sourceVector{ 1,2,3,4,5 };
|
||||
AZStd::fixed_vector<int, 32> sourceVector{ 1,2,3,4,5 };
|
||||
|
||||
AZStd::fixed_vector<int, 8> copyConstructVector{ sourceVector };
|
||||
EXPECT_EQ(sourceVector, copyConstructVector);
|
||||
@@ -768,32 +768,32 @@ namespace UnitTest
|
||||
|
||||
AZStd::fixed_vector<int, 16> moveAssignVector = AZStd::move(moveConstructVector);
|
||||
|
||||
constexpr AZStd::fixed_vector expectedVector{ 1,2,3,4,5,6 };
|
||||
AZStd::fixed_vector expectedVector{ 1,2,3,4,5,6 };
|
||||
EXPECT_EQ(expectedVector, moveAssignVector);
|
||||
}
|
||||
|
||||
TEST_F(Arrays, FixedVectorComparisonOperatorsSucceedAsExpected)
|
||||
{
|
||||
constexpr AZStd::fixed_vector<int, 32> testVector{ 1,2,3,4,5 };
|
||||
constexpr AZStd::fixed_vector<int, 32> equalVector{ 1,2,3,4,5 };
|
||||
constexpr AZStd::fixed_vector<int, 32> notEqualVectorDifferentSize{ 1,2,3,4,5,6 };
|
||||
constexpr AZStd::fixed_vector<int, 32> lessVector{ 1,2,3,4,4 };
|
||||
constexpr AZStd::fixed_vector<int, 32> greaterVectorDifferentSize{ 1,2,3,4,5, 1 };
|
||||
AZStd::fixed_vector<int, 32> testVector{ 1,2,3,4,5 };
|
||||
AZStd::fixed_vector<int, 32> equalVector{ 1,2,3,4,5 };
|
||||
AZStd::fixed_vector<int, 32> notEqualVectorDifferentSize{ 1,2,3,4,5,6 };
|
||||
AZStd::fixed_vector<int, 32> lessVector{ 1,2,3,4,4 };
|
||||
AZStd::fixed_vector<int, 32> greaterVectorDifferentSize{ 1,2,3,4,5, 1 };
|
||||
|
||||
static_assert(testVector == equalVector);
|
||||
static_assert(testVector != notEqualVectorDifferentSize);
|
||||
static_assert(testVector != lessVector);
|
||||
static_assert(lessVector < testVector);
|
||||
static_assert(lessVector < greaterVectorDifferentSize);
|
||||
static_assert(lessVector <= lessVector);
|
||||
static_assert(lessVector <= testVector);
|
||||
static_assert(lessVector <= greaterVectorDifferentSize);
|
||||
static_assert(testVector > lessVector);
|
||||
static_assert(testVector > lessVector);
|
||||
static_assert(notEqualVectorDifferentSize > testVector);
|
||||
static_assert(testVector >= testVector);
|
||||
static_assert(testVector >= lessVector);
|
||||
static_assert(greaterVectorDifferentSize > lessVector);
|
||||
EXPECT_EQ(testVector, equalVector);
|
||||
EXPECT_NE(testVector, notEqualVectorDifferentSize);
|
||||
EXPECT_NE(testVector, lessVector);
|
||||
EXPECT_LT(lessVector, testVector);
|
||||
EXPECT_LT(lessVector, greaterVectorDifferentSize);
|
||||
EXPECT_LE(lessVector, lessVector);
|
||||
EXPECT_LE(lessVector, testVector);
|
||||
EXPECT_LE(lessVector, greaterVectorDifferentSize);
|
||||
EXPECT_GT(testVector, lessVector);
|
||||
EXPECT_GT(testVector, lessVector);
|
||||
EXPECT_GT(notEqualVectorDifferentSize, testVector);
|
||||
EXPECT_GE(testVector, testVector);
|
||||
EXPECT_GE(testVector, lessVector);
|
||||
EXPECT_GT(greaterVectorDifferentSize, lessVector);
|
||||
}
|
||||
|
||||
TEST_F(Arrays, VectorSwap)
|
||||
|
||||
Reference in New Issue
Block a user