Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ dev = [
"pytest",
"pytest-cov",
"ruff",
"tox-gh-actions"
"tox-gh-actions",
"psutil"
]
docs = [
"doc8",
Expand Down
13 changes: 13 additions & 0 deletions src/easyscience/global_object/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def add_vertex(self, obj: object, obj_type: str = None):
name = obj.unique_name
if name in self._store.keys():
raise ValueError(f'Object name {name} already exists in the graph.')

self._store[name] = obj
self.__type_dict[name] = _EntryList() # Add objects type to the list of types
self.__type_dict[name].finalizer = weakref.finalize(self._store[name], self.prune, name)
Expand Down Expand Up @@ -261,6 +262,18 @@ def is_connected(self, vertices_encountered=None, start_vertex=None) -> bool:
return False

def _clear(self):
"""Reset the map to an empty state."""
# Fast bulk clear instead of iterating through vertices
store_size = len(self._store)
self._store.clear()
self.__type_dict.clear()
# Only collect garbage if there were many objects
# value chosen based on performance testing in
# tests/performance/gc_threshold_strategy.py
if store_size > 100:
gc.collect()

def _clear_old(self):
"""Reset the map to an empty state."""
for vertex in self.vertices():
self.prune(vertex)
Expand Down
Loading
Loading