Tips for performance issues when removing from collections?
Here is an image from a profiler of a single object removal taking ~3ms in a Release build.
You can see the perf macro matching that span (though was renamed after the screenshot); when I find the desired item, I remove it from three Observable Collections:
Obviously knowing exactly what I have in XAML would be good but there's a lot to go through. Are there some best practices at least? Would help me narrow down on dumb things I'm doing that could cause this - I don't understand how e.g. DependencyObject::OnDestroy could end up taking 1ms. I'm on version 3.0.12 btw.
Side-note: it'd be nice if I could remove a bunch of items from an Observable Collection and only then trigger a dirty/refresh, rather than on each individual change; is that possible?
You can see the perf macro matching that span (though was renamed after the screenshot); when I find the desired item, I remove it from three Observable Collections:
Code: Select all
void GameViewModel::RemoveSpaceObject(Entity entity)
{
for (int i = 0; i < entities_->Count(); ++i)
{
EntityViewModel* model = entities_->Get(i);
if (model->GetEntityID() == entity.GetID())
{
RTG_PROFILE_EVENT("GameViewModel Removing Space Object");
const int indexInPlayerEntities = playerEntities_->IndexOf(model);
if (indexInPlayerEntities != -1)
{
playerEntities_->RemoveAt(indexInPlayerEntities); // Noesis::Ptr<Noesis::ObservableCollection<EntityViewModel>>
}
entities_->Remove(model); // Noesis::Ptr<Noesis::ObservableCollection<EntityViewModel>>
if (const ClientPredictionViewModelComponent* pPredictionViewModelComponent = entity.TryGetComponent<const ClientPredictionViewModelComponent>())
{
predictionsViewModel_->GetPredictions()->Remove(pPredictionViewModelComponent->GetConst()); // Noesis::Ptr<Noesis::ObservableCollection<ClientPredictionViewModel>>
}
break;
}
}
}
Side-note: it'd be nice if I could remove a bunch of items from an Observable Collection and only then trigger a dirty/refresh, rather than on each individual change; is that possible?
-
sfernandez
Site Admin
- Posts: 3093
- Joined:
Re: Tips for performance issues when removing from collections?
Hi, could you please open a ticket about this in our bugtracker?
We've been recently working on some optimizations on that front and I can provide some patched libraries for you to try.
We've been recently working on some optimizations on that front and I can provide some patched libraries for you to try.
Who is online
Users browsing this forum: Ahrefs [Bot] and 6 guests