From b4bc7ec371bb0cfb68c6eda542c427ad5a924dc9 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 10 Jun 2025 18:06:59 +0500 Subject: [PATCH] remove_deep2 optimization for cases when the same entity is referenced by multiple other in the subgraph #6784 --- src/ifcopenshell-python/ifcopenshell/util/element.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 0299eecb69..825befdb7b 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -1597,10 +1597,17 @@ def remove_deep2( subgraph.extend(also_consider) subgraph_set = set(subgraph) subelement_queue = [element] + + # Cache already processed entities to avoid traversing them multiple time. + # E.g. lots of IFCINDEXEDPOLYCURVES may reference the same IFCCARTESIANPOINTLIST2D. + processed_ids: set[int] = set() + while subelement_queue: subelement = subelement_queue.pop(0) + subelement_id = subelement.id() if ( - subelement.id() + subelement_id + and subelement_id not in processed_ids and subelement not in do_not_delete and ( # 0 or 1 inverses guarantees that the subelement only exists in this subgraph @@ -1623,6 +1630,7 @@ def remove_deep2( for i, attribute in enumerate(subelement): if isinstance(attribute, tuple) and len(attribute) > 10: subelement[i] = [] + processed_ids.add(subelement_id) if ifc_file.to_delete is not None: ifc_file.to_delete.update(to_delete)