mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 22:44:34 +00:00
Add zone vector cache.
Zone children will be now collected in staging vectors. When the zone is ended (and no children can be added anymore to it), a size-fitted vector is allocated using slab allocation. The over-allocated vector is then put into cache for use in future zones. This is only active for vectors <= 8192 elements, or 64 KB (chosen arbitrarily), to reduce time spent on copying memory. Overall, this change should have the following effects: - System memory allocation pressure reduction, due to re-usage of vectors, which eliminates the need for constant growth. - Reduction of memory usage, because children vectors are now fitted to required size. - Slight increase of zone processing time, due to memory copying?
This commit is contained in:
parent
11f4dcbf1e
commit
a632d9e2a3
@ -1978,7 +1978,18 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
|
||||
if( back->child < 0 )
|
||||
{
|
||||
back->child = int32_t( m_data.zoneChildren.size() );
|
||||
m_data.zoneChildren.push_back( Vector<ZoneEvent*>( zone ) );
|
||||
if( m_data.zoneVectorCache.empty() )
|
||||
{
|
||||
m_data.zoneChildren.push_back( Vector<ZoneEvent*>( zone ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector<ZoneEvent*> vze = std::move( m_data.zoneVectorCache.back_and_pop() );
|
||||
assert( !vze.empty() );
|
||||
vze.clear();
|
||||
vze.push_back_non_empty( zone );
|
||||
m_data.zoneChildren.push_back( std::move( vze ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2613,6 +2624,20 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
|
||||
|
||||
m_data.lastTime = std::max( m_data.lastTime, zone->end );
|
||||
|
||||
if( zone->child >= 0 )
|
||||
{
|
||||
auto& childVec = m_data.zoneChildren[zone->child];
|
||||
const auto sz = childVec.size();
|
||||
if( sz <= 8 * 1024 )
|
||||
{
|
||||
Vector<ZoneEvent*> fitVec;
|
||||
fitVec.reserve_exact( sz, m_slab );
|
||||
memcpy( fitVec.data(), childVec.data(), sz * sizeof( ZoneEvent* ) );
|
||||
std::swap( fitVec, childVec );
|
||||
m_data.zoneVectorCache.push_back( std::move( fitVec ) );
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef TRACY_NO_STATISTICS
|
||||
auto timeSpan = zone->end - zone->start;
|
||||
if( timeSpan > 0 )
|
||||
|
@ -178,6 +178,8 @@ private:
|
||||
Vector<Vector<ZoneEvent*>> zoneChildren;
|
||||
Vector<Vector<GpuEvent*>> gpuChildren;
|
||||
|
||||
Vector<Vector<ZoneEvent*>> zoneVectorCache;
|
||||
|
||||
CrashEvent crashEvent;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user