@@ -38,6 +38,8 @@ class BufferManager:
3838 List of transformation matrices for each object
3939 settings : List[float]
4040 List of setting values for each object
41+ object_settings_cache : Dict[Any, List[float]]
42+ Cache for object settings to avoid redundant GPU updates
4143 """
4244
4345 def __init__ (self ):
@@ -56,6 +58,7 @@ def __init__(self):
5658
5759 # Settings data
5860 self .settings : List [float ] = []
61+ self .object_settings_cache : Dict [Any , List [float ]] = {}
5962
6063 # Initialize empty buffers for each geometry type
6164 for buffer_type in ["_points_data" , "_lines_data" , "_frontfaces_data" , "_backfaces_data" ]:
@@ -265,6 +268,7 @@ def clear(self) -> None:
265268
266269 self .transforms = []
267270 self .settings = []
271+ self .object_settings_cache = {}
268272
269273 def update_object_transform (self , obj : Any ) -> None :
270274 """Update the transformation matrix for a single object.
@@ -359,6 +363,13 @@ def update_object_settings(self, obj: Any) -> None:
359363 [* instance_color , obj .is_selected ], # Row 2
360364 [parent_index , obj .opacity , obj .pointsize , getattr (obj , "linewidth" , 1.0 )], # Row 3: parent index and padding
361365 ]
366+
367+ # Check against cache to avoid unnecessary GPU updates
368+ if self .object_settings_cache .get (obj ) == obj_settings :
369+ return
370+
371+ # If settings have changed, update the GPU buffer and the cache
372+ self .object_settings_cache [obj ] = obj_settings
362373 index = self .objects [obj ]
363374 self .settings [index ] = obj_settings
364375 byte_offset = index * 4 * 12 # 3 rows * 4 floats per row * 4 bytes per float
0 commit comments