Optimize scenes loading with Job System

This commit is contained in:
Wojtek Figat
2023-10-01 10:55:01 +02:00
parent f77198c7ca
commit b960600102
11 changed files with 162 additions and 69 deletions

View File

@@ -8,6 +8,7 @@ CollectionPoolCache<ISerializeModifier, Cache::ISerializeModifierClearCallback>
void Cache::ISerializeModifierClearCallback(::ISerializeModifier* obj)
{
obj->EngineBuild = FLAXENGINE_VERSION_BUILD;
obj->CurrentInstance = -1;
obj->IdsMapping.Clear();
}

View File

@@ -49,7 +49,7 @@ public:
private:
CollectionPoolCache* _pool;
ScopeCache(CollectionPoolCache* pool, T* value)
FORCE_INLINE ScopeCache(CollectionPoolCache* pool, T* value)
{
_pool = pool;
Value = value;
@@ -71,7 +71,7 @@ public:
~ScopeCache()
{
_pool->Release(Value);
_pool->Put(Value);
}
T* operator->()
@@ -99,13 +99,6 @@ private:
CriticalSection _locker;
Array<T*, InlinedAllocation<64>> _pool;
void Release(T* value)
{
_locker.Lock();
_pool.Add(value);
_locker.Unlock();
}
public:
/// <summary>
/// Finalizes an instance of the <see cref="CollectionPoolCache"/> class.
@@ -120,7 +113,16 @@ public:
/// Gets the collection instance from the pool. Can reuse the object from the pool or create a new one. Returns collection is always cleared and ready to use.
/// </summary>
/// <returns>The collection (cleared).</returns>
ScopeCache Get()
FORCE_INLINE ScopeCache Get()
{
return ScopeCache(this, GetUnscoped());
}
/// <summary>
/// Gets the collection instance from the pool. Can reuse the object from the pool or create a new one. Returns collection is always cleared and ready to use.
/// </summary>
/// <returns>The collection (cleared).</returns>
T* GetUnscoped()
{
T* result;
_locker.Lock();
@@ -129,10 +131,18 @@ public:
else
result = CreateCallback();
_locker.Unlock();
ClearCallback(result);
return result;
}
return ScopeCache(this, result);
/// <summary>
/// Puts the collection value back to the pool.
/// </summary>
void Put(T* value)
{
_locker.Lock();
_pool.Add(value);
_locker.Unlock();
}
/// <summary>

View File

@@ -785,12 +785,11 @@ public:
/// <param name="other">The other collection to clone.</param>
void Clone(const Dictionary& other)
{
// TODO: if both key and value are POD types then use raw memory copy for buckets
Clear();
SetCapacity(other.Capacity(), false);
EnsureCapacity(other.Capacity(), false);
for (Iterator i = other.Begin(); i != other.End(); ++i)
Add(i);
ASSERT(Count() == other.Count());
ASSERT(Capacity() == other.Capacity());
}
/// <summary>