Possible optimisation by caching in IfcTester property checks

This commit is contained in:
Dion Moult
2023-09-26 16:02:59 +10:00
parent 4fda95a4a6
commit 06c2b06f7c
2 changed files with 16 additions and 3 deletions
+13 -2
View File
@@ -21,6 +21,7 @@ import builtins
import ifcopenshell.util.unit import ifcopenshell.util.unit
import ifcopenshell.util.element import ifcopenshell.util.element
import ifcopenshell.util.classification import ifcopenshell.util.classification
from functools import lru_cache
from xmlschema.validators import identities from xmlschema.validators import identities
@@ -41,6 +42,16 @@ def cast_to_value(from_value, to_value):
pass pass
@lru_cache
def get_pset(element, pset):
return ifcopenshell.util.element.get_pset(element, pset)
@lru_cache
def get_psets(element, pset):
return ifcopenshell.util.element.get_psets(element)
class Facet: class Facet:
def __init__(self, *parameters): def __init__(self, *parameters):
self.status = None self.status = None
@@ -591,10 +602,10 @@ class Property(Facet):
return PropertyResult(True) return PropertyResult(True)
if isinstance(self.propertySet, str): if isinstance(self.propertySet, str):
pset = ifcopenshell.util.element.get_pset(inst, self.propertySet) pset = get_pset(inst, self.propertySet)
psets = {self.propertySet: pset} if pset else {} psets = {self.propertySet: pset} if pset else {}
else: else:
all_psets = ifcopenshell.util.element.get_psets(inst) all_psets = get_psets(inst)
psets = {k: v for k, v in all_psets.items() if k == self.propertySet} psets = {k: v for k, v in all_psets.items() if k == self.propertySet}
is_pass = bool(psets) is_pass = bool(psets)
+3 -1
View File
@@ -21,7 +21,7 @@ import datetime
from xmlschema import XMLSchema from xmlschema import XMLSchema
from xmlschema import etree_tostring from xmlschema import etree_tostring
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
from .facet import Entity, Attribute, Classification, Property, PartOf, Material, Restriction from .facet import Entity, Attribute, Classification, Property, PartOf, Material, Restriction, get_pset, get_psets
cwd = os.path.dirname(os.path.realpath(__file__)) cwd = os.path.dirname(os.path.realpath(__file__))
@@ -113,6 +113,8 @@ class Ids:
return get_schema().is_valid(filepath) return get_schema().is_valid(filepath)
def validate(self, ifc_file, filter_version=False): def validate(self, ifc_file, filter_version=False):
get_pset.cache_clear()
get_psets.cache_clear()
for specification in self.specifications: for specification in self.specifications:
specification.reset_status() specification.reset_status()
specification.validate(ifc_file, filter_version=filter_version) specification.validate(ifc_file, filter_version=filter_version)