summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2020-08-10 13:32:57 +0300
committerAntti Määttä <antti.maatta@qt.io>2020-08-11 13:00:47 +0300
commitb43e39c8a20e781a1b9ed24ad0bd963d06a5d1c1 (patch)
treefb28e601ab9114058a8c6610175f76eac3551381
parente1dc670f9a804a82ccad3f8caf80656a966dc16b (diff)
Optimize runtime performance
- Reduce allocations by reducing std::pair usage. - Reduce allocations by not caching parents. - Some smaller optimizations Task-number: QT3DS-4151 Change-Id: I0bf770069b23ca4715f5f98ab3b35001156fe8fc Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
-rw-r--r--src/dm/systems/Qt3DSDMMetaData.cpp5
-rw-r--r--src/dm/systems/Qt3DSDMSlideCore.h45
-rw-r--r--src/dm/systems/SlideSystem.cpp5
-rw-r--r--src/dm/systems/cores/DataCoreProducer.cpp16
-rw-r--r--src/dm/systems/cores/SimpleDataCore.h24
-rw-r--r--src/dm/systems/cores/SimpleSlideCore.h27
-rw-r--r--src/dm/systems/cores/SlideCoreProducer.cpp5
7 files changed, 61 insertions, 66 deletions
diff --git a/src/dm/systems/Qt3DSDMMetaData.cpp b/src/dm/systems/Qt3DSDMMetaData.cpp
index 0db75da..5ac78e8 100644
--- a/src/dm/systems/Qt3DSDMMetaData.cpp
+++ b/src/dm/systems/Qt3DSDMMetaData.cpp
@@ -1429,8 +1429,9 @@ public:
Qt3DSDMMetaDataPropertyHandle GetMetaDataProperty(Qt3DSDMInstanceHandle inInstance,
Qt3DSDMPropertyHandle inProperty) override
{
- Qt3DSDMPropertyDefinition propDef(m_DataCore->GetProperty(inProperty));
- return GetMetaDataProperty(inInstance, propDef.m_Name);
+ const Qt3DSDMPropertyDefinition &propDef = m_DataCore->GetProperty(inProperty);
+ return FindItemByName<Qt3DSDMMetaDataPropertyHandle>(inInstance, Intern(propDef.m_Name),
+ m_InstanceNameToProperties);
}
// Sets the value in the data core
virtual Option<SMetaDataPropertyInfo>
diff --git a/src/dm/systems/Qt3DSDMSlideCore.h b/src/dm/systems/Qt3DSDMSlideCore.h
index 6e32a56..743774f 100644
--- a/src/dm/systems/Qt3DSDMSlideCore.h
+++ b/src/dm/systems/Qt3DSDMSlideCore.h
@@ -34,9 +34,36 @@
#include "HandleSystemBase.h"
#include "Qt3DSDMStringTable.h"
#include "Qt3DSDMDataCore.h"
+#include <QtCore/qdebug.h>
+
namespace qt3dsdm {
-typedef std::pair<Qt3DSDMInstanceHandle, Qt3DSDMPropertyHandle> TInstancePropertyPair;
+
+struct TInstancePropertyPair {
+ int first;
+ int second;
+ TInstancePropertyPair() : first(0), second(0) {
+
+ }
+ TInstancePropertyPair(int _first, int _second) : first(_first), second(_second) {
+
+ }
+ TInstancePropertyPair(const TInstancePropertyPair &pa)
+ : first(pa.first), second(pa.second)
+ {
+
+ }
+ friend bool operator == (const TInstancePropertyPair& pa1, const TInstancePropertyPair& pa2)
+ {
+ return pa1.first == pa2.first && pa1.second == pa2.second;
+ }
+ friend QDebug operator << (QDebug &debug, const TInstancePropertyPair &pair)
+ {
+ debug << pair.first << " " << pair.second;
+ return debug;
+ }
+};
+
typedef std::vector<TInstancePropertyPair> TInstancePropertyPairList;
// instance,property,value
@@ -236,4 +263,20 @@ public:
typedef std::shared_ptr<ISlideCore> TSlideCorePtr;
}
+namespace std {
+
+template<> struct hash<qt3dsdm::TInstancePropertyPair >
+{
+ typedef qt3dsdm::TInstancePropertyPair argument_type;
+ typedef std::size_t result_type;
+ result_type operator()(argument_type const& pa) const
+ {
+ result_type const h1 ( std::hash<int>{}(pa.first) );
+ result_type const h2 ( std::hash<int>{}(pa.second) );
+ return h1 ^ (h2 << 1);
+ }
+};
+
+}
+
#endif
diff --git a/src/dm/systems/SlideSystem.cpp b/src/dm/systems/SlideSystem.cpp
index c24e2c7..0a4248e 100644
--- a/src/dm/systems/SlideSystem.cpp
+++ b/src/dm/systems/SlideSystem.cpp
@@ -139,7 +139,7 @@ void SetEntryValueIfNotReferenced(const TSlideEntry &inEntry,
else
inDestCore->ForceSetInstancePropertyValue(inDestSlide, get<0>(inEntry), get<1>(inEntry),
get<2>(inEntry));
- CopyAnimationIfExist(inSource, inDestSlide, make_pair(get<0>(inEntry), get<1>(inEntry)),
+ CopyAnimationIfExist(inSource, inDestSlide, TInstancePropertyPair(get<0>(inEntry), get<1>(inEntry)),
inPropertySystem, inAnimationCore);
}
@@ -614,7 +614,8 @@ void SSlideSystem::UnlinkProperty(Qt3DSDMInstanceHandle inInstance, Qt3DSDMPrope
std::placeholders::_1,
inInstance, inProperty, theValue));
do_all(theChildren,
- std::bind(CopyAnimationIfExist, theSlide, std::placeholders::_1, make_pair(inInstance, inProperty),
+ std::bind(CopyAnimationIfExist, theSlide, std::placeholders::_1,
+ TInstancePropertyPair(inInstance, inProperty),
m_PropertySystem, m_AnimationCore));
}
GetSignalSender()->SendPropertyUnlinked(theSlide, inInstance, inProperty);
diff --git a/src/dm/systems/cores/DataCoreProducer.cpp b/src/dm/systems/cores/DataCoreProducer.cpp
index 5c3cc92..e74f95e 100644
--- a/src/dm/systems/cores/DataCoreProducer.cpp
+++ b/src/dm/systems/cores/DataCoreProducer.cpp
@@ -109,19 +109,6 @@ void CDataCoreProducer::GetInstancesDerivedFrom(TInstanceHandleList &outInstance
m_Data->GetInstancesDerivedFrom(outInstances, inParentHandle);
}
-struct ClearInstanceParentCacheTransaction : public ITransaction
-{
- const CDataModelInstance &m_Instance;
- ClearInstanceParentCacheTransaction(const char *inFile, int inLine,
- const CDataModelInstance &inst)
- : ITransaction(inFile, inLine)
- , m_Instance(inst)
- {
- }
- void Do() override { m_Instance.ClearParentCache(); }
- void Undo() override { m_Instance.ClearParentCache(); }
-};
-
void CDataCoreProducer::DeriveInstance(Qt3DSDMInstanceHandle inInstance,
Qt3DSDMInstanceHandle inParent)
{
@@ -134,9 +121,6 @@ void CDataCoreProducer::DeriveInstance(Qt3DSDMInstanceHandle inInstance,
make_pair(inParent.GetHandleValue(),
CSimpleDataCore::GetInstanceNF(inParent, m_Data->m_Objects)),
theInstance->m_Parents);
- m_Consumer->OnTransaction(std::static_pointer_cast<ITransaction>(
- std::make_shared<ClearInstanceParentCacheTransaction>(__FILE__, __LINE__,
- *theInstance)));
}
GetDataCoreSender()->SignalInstanceDerived(inInstance, inParent);
}
diff --git a/src/dm/systems/cores/SimpleDataCore.h b/src/dm/systems/cores/SimpleDataCore.h
index 2664dab..fd4e51a 100644
--- a/src/dm/systems/cores/SimpleDataCore.h
+++ b/src/dm/systems/cores/SimpleDataCore.h
@@ -101,7 +101,6 @@ public:
typedef std::unordered_map<int, bool> TInstanceParentMap;
TInstancePairList m_Parents;
- mutable TInstanceParentMap m_CachedParents;
// Properties specific to this class
TIntList m_Properties;
TPropertyPairHash m_PropertyValues;
@@ -128,33 +127,20 @@ public:
m_PropertyValues.insert(*iter);
}
- void ClearParentCache() const { m_CachedParents.clear(); }
+ void ClearParentCache() const { }
bool IsDerivedFrom(Qt3DSDMInstanceHandle inParent) const
{
- std::pair<TInstanceParentMap::iterator, bool> theQueryResult =
- m_CachedParents.insert(std::make_pair(inParent.GetHandleValue(), false));
- // If the insert failed, returned what the hashtable already had in it
- if (theQueryResult.second == false)
- return theQueryResult.first->second;
-
- // Else find a valid answer
if (m_Parents.find(inParent.GetHandleValue()) != m_Parents.end()) {
- theQueryResult.first->second = true;
+ return true;
} else {
for (TInstancePairList::const_iterator iter = m_Parents.begin(), end = m_Parents.end();
iter != end; ++iter) {
- if (iter->second->IsDerivedFrom(inParent)) {
- theQueryResult.first->second = true;
- break;
- }
+ if (iter->second->IsDerivedFrom(inParent))
+ return true;
}
}
-
- // Note that we inserted false to begin with. This means that
- // we can return the insert result here safely as if it wasn't
- // supposed to be false, we would have set it above.
- return theQueryResult.first->second;
+ return false;
}
void RemoveCachedValues()
diff --git a/src/dm/systems/cores/SimpleSlideCore.h b/src/dm/systems/cores/SimpleSlideCore.h
index effa3bd..6c33422 100644
--- a/src/dm/systems/cores/SimpleSlideCore.h
+++ b/src/dm/systems/cores/SimpleSlideCore.h
@@ -36,30 +36,11 @@
#include <unordered_map>
#include <QtCore/qdebug.h>
-namespace std {
-
-template<> struct hash<std::pair<int,int> >
-{
- typedef std::pair<int,int> argument_type;
- typedef std::size_t result_type;
- result_type operator()(std::pair<int,int> const& pa) const
- {
- result_type const h1 ( std::hash<int>{}(pa.first) );
- result_type const h2 ( std::hash<int>{}(pa.second) );
- return h1 ^ (h2 << 1);
- }
-};
-
-}
-
namespace qt3dsdm {
-// The first revision of this
-typedef std::pair<int, int> TSlideInstancePropertyPair;
+typedef TInstancePropertyPair TSlideInstancePropertyPair;
typedef std::unordered_map<TSlideInstancePropertyPair, SInternValue > TSlideEntryHash;
-using std::make_pair;
-
// Abstract access to these objects a little bit because in the future we are going to
// reorganize the data such that getting a defined set of properties for a single instance is
// very fast.
@@ -111,7 +92,7 @@ struct SSlide : public CHandleObject
SInternValue *GetInstancePropertyValue(Qt3DSDMInstanceHandle inInstance,
Qt3DSDMPropertyHandle inProperty) const
{
- TSlideInstancePropertyPair theKey(inInstance.GetHandleValue(), inProperty.GetHandleValue());
+ const TSlideInstancePropertyPair theKey(inInstance.GetHandleValue(), inProperty.GetHandleValue());
TSlideEntryHash::const_iterator find(m_Properties.find(theKey));
if (find != m_Properties.end())
return const_cast<SInternValue *>(&find->second);
@@ -126,7 +107,7 @@ struct SSlide : public CHandleObject
theIter != theEnd; ++theIter) {
if (theIter->first.first == inInstance)
outProperties.push_back(
- make_pair(theIter->first.second, theIter->second.GetValue()));
+ std::make_pair(theIter->first.second, theIter->second.GetValue()));
}
}
@@ -161,7 +142,7 @@ struct SSlide : public CHandleObject
{
for (size_t idx = 0, end = inList.size(); idx < end; ++idx)
m_Properties.erase(
- std::pair<int, int>(std::get<0>(inList[idx]), std::get<1>(inList[idx])));
+ TSlideInstancePropertyPair(std::get<0>(inList[idx]), std::get<1>(inList[idx])));
}
void InsertSlideEntries(const TSlideEntryList &inList, IStringTable &inStringTable)
diff --git a/src/dm/systems/cores/SlideCoreProducer.cpp b/src/dm/systems/cores/SlideCoreProducer.cpp
index 75b7c69..4177b69 100644
--- a/src/dm/systems/cores/SlideCoreProducer.cpp
+++ b/src/dm/systems/cores/SlideCoreProducer.cpp
@@ -203,7 +203,6 @@ struct HashMapDataValueInsertTransaction
}
void Do() override
{
- std::pair<int, int> theKey = m_Value.first;
SValue theTempValue = m_Value.second.GetValue();
TDataStrPtr theStrPtr;
if (GetValueType(theTempValue) == DataModelDataType::String) {
@@ -223,7 +222,7 @@ inline void CSlideCoreProducer::DoForceSetInstancePropertyValue(Qt3DSDMSlideHand
SInternValue theNewValue(inValue, m_Data->GetStringTable());
SInternValue *theCurrentValue(theSlide->GetInstancePropertyValue(inHandle, inProperty));
- std::pair<int, int> theKey(inHandle, inProperty);
+ const TInstancePropertyPair theKey(inHandle, inProperty);
SlideInstancePropertyKey mergeMapKey(inSlide, inHandle, inProperty);
TSlidePropertyMergeMap::iterator iter = m_PropertyMergeMap.find(mergeMapKey);
if (iter != m_PropertyMergeMap.end()) {
@@ -322,7 +321,7 @@ inline void ClearValueWithTransactions(TTransactionConsumerPtr inConsumer,
SInternValue *theCurrentValue(theSlide->GetInstancePropertyValue(inHandle, inProperty));
if (theCurrentValue) {
SValue theValue(theCurrentValue->GetValue());
- std::pair<int, int> theKey(inHandle, inProperty);
+ TInstancePropertyPair theKey(inHandle, inProperty);
CreateHashMapEraseTransaction(__FILE__, __LINE__, inConsumer,
std::make_pair(theKey, *theCurrentValue),
theSlide->m_Properties);