mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
Wrap tool.System.get_decoration_data with TokenCache lookup
System decoration draws on every viewport refresh — the ``_build_decoration_data`` body walks every distribution element, resolves connected ports, builds the vert/edge arrays for the GPU batch. A bare call per frame burns time on an unchanged scene. Add a single-entry cache keyed on ``(decorator_cache_token, id(decorated_elements_set))``. Reads short-circuit when neither component moved: * ``decorator_cache_token`` from ``bim.decorator_cache`` invalidates on depsgraph / undo / redo / load via the bump handler. * ``id(decorated_elements_set)`` invalidates when ``SystemDecorationData.load()`` reassigns the set (e.g. when the user changes the set of decorated systems via the panel). The handler that bumps the token is installed in the next commit (bim/handler.py decompose). Until then the token stays at 0, so the cache only hits when ``id()`` also matches — degraded behaviour during the bisect window but not incorrect. Generated with the assistance of an AI coding tool.
This commit is contained in:
committed by
Thomas Krijnen
parent
3f9ecbeda1
commit
f7db539fcd
@@ -299,15 +299,29 @@ class System(bonsai.core.tool.System):
|
||||
system_props = cls.get_system_props()
|
||||
return tool.Ifc.get_entity_by_id(system_props.active_system_id)
|
||||
|
||||
# Decoration-data cache, keyed on (decorator_cache_token, id(decorated_elements_set)).
|
||||
_decoration_data_cache_key: tuple | None = None
|
||||
_decoration_data_cache: dict[str, Any] | None = None
|
||||
|
||||
@classmethod
|
||||
def get_decoration_data(cls) -> dict[str, Any]:
|
||||
from bonsai.bim.decorator_cache import get_decorator_cache_token
|
||||
from bonsai.bim.module.system.data import ObjectSystemData, SystemDecorationData
|
||||
|
||||
if not ObjectSystemData.is_loaded:
|
||||
ObjectSystemData.load()
|
||||
if not SystemDecorationData.is_loaded:
|
||||
SystemDecorationData.load()
|
||||
return cls._build_decoration_data()
|
||||
|
||||
token = get_decorator_cache_token()
|
||||
key = (token, id(SystemDecorationData.data["decorated_elements"]))
|
||||
if key == cls._decoration_data_cache_key and cls._decoration_data_cache is not None:
|
||||
return cls._decoration_data_cache
|
||||
|
||||
result = cls._build_decoration_data()
|
||||
cls._decoration_data_cache_key = key
|
||||
cls._decoration_data_cache = result
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def _build_decoration_data(cls) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user