Skip to content

Commit

Permalink
19170: Fixes issues with memory scaling, including rare crash (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
howsohazard authored Jan 25, 2024
1 parent d8d3d64 commit bf5fc88
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Amalgam/SeparableBoxFilterDataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class SeparableBoxFilterDataStore
void BuildLabel(size_t column_index, const std::vector<Entity *> &entities);

//changes column to/from interning as would yield best performance
void OptimizeColumn(size_t column_ndex);
void OptimizeColumn(size_t column_index);

//calls OptimizeColumn on all columns
inline void OptimizeAllColumns()
Expand Down
2 changes: 1 addition & 1 deletion src/Amalgam/entity/EntityQueryCaches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void EntityQueryCaches::EnsureLabelsAreCached(EntityQueryCondition *cond)
lock.unlock();
Concurrency::WriteLock write_lock(mutex);

//now with write_lock, remove any labels that might have already been added by other threads
//now with write_lock, remove any labels that have already been added by other threads
labels_to_add.erase(std::remove_if(begin(labels_to_add), end(labels_to_add),
[this](auto sid) { return DoesHaveLabel(sid); }),
end(labels_to_add));
Expand Down
14 changes: 7 additions & 7 deletions src/Amalgam/evaluablenode/EvaluableNodeManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ EvaluableNode *EvaluableNodeManager::AllocListNodeWithOrderedChildNodes(Evaluabl
//if don't currently have enough free nodes to meet the needs, then expand the allocation
if(num_nodes_needed > num_nodes)
{
size_t nodes_to_allocate = static_cast<size_t>(allocExpansionFactor * num_nodes_needed) + 1;
size_t new_num_nodes = static_cast<size_t>(allocExpansionFactor * num_nodes_needed) + 1;

//fill new EvaluableNode slots with nullptr
nodes.resize(num_nodes + nodes_to_allocate, nullptr);
nodes.resize(new_num_nodes, nullptr);
}
}

Expand Down Expand Up @@ -285,7 +285,7 @@ EvaluableNode *EvaluableNodeManager::AllocUninitializedNode()
#ifdef MULTITHREAD_SUPPORT
//before releasing the lock, make sure it has an allocated type, otherwise it could get grabbed by another thread
nodes[firstUnusedNodeIndex]->InitializeUnallocated();
#endif
#endif
}
else //allocate if nullptr
nodes[firstUnusedNodeIndex] = new EvaluableNode();
Expand All @@ -294,10 +294,10 @@ EvaluableNode *EvaluableNodeManager::AllocUninitializedNode()
}

//ran out, so need another node; push a bunch on the heap so don't need to reallocate as often and slow down garbage collection
size_t nodes_to_allocate = static_cast<size_t>(allocExpansionFactor * num_nodes) + 1; //preallocate additional resources, plus current node
size_t new_num_nodes = static_cast<size_t>(allocExpansionFactor * num_nodes) + 1; //preallocate additional resources, plus current node

//fill new EvaluableNode slots with nullptr
nodes.resize(num_nodes + nodes_to_allocate, nullptr);
nodes.resize(new_num_nodes, nullptr);

if(nodes[firstUnusedNodeIndex] != nullptr)
{
Expand Down Expand Up @@ -335,14 +335,14 @@ void EvaluableNodeManager::FreeAllNodesExceptReferencedNodes()
auto &cur_node_ptr = nodes[first_unused_node_index_temp];

//if the node has been found on this iteration and set to the current iteration count, then move on
if(cur_node_ptr->GetGarbageCollectionIteration() == cur_gc_collect_iteration)
if(cur_node_ptr != nullptr && cur_node_ptr->GetGarbageCollectionIteration() == cur_gc_collect_iteration)
{
first_unused_node_index_temp++;
}
else //collect the node
{
//free any extra memory used, since this node is no longer needed
if(cur_node_ptr->GetType() != ENT_DEALLOCATED)
if(cur_node_ptr != nullptr && cur_node_ptr->GetType() != ENT_DEALLOCATED)
cur_node_ptr->Invalidate();

//see if out of things to free; if so exit early
Expand Down

0 comments on commit bf5fc88

Please sign in to comment.