Skip to content

Commit 3f49f7b

Browse files
committed
Performance optimization: remove unnecessary reentrant lock from CachedProperty
PiperOrigin-RevId: 239083279
1 parent eb9706d commit 3f49f7b

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

dm_control/mujoco/wrapper/util.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import os
2626
import platform
2727
import sys
28-
import threading
2928
from dm_control import _render
3029
import numpy as np
3130
import six
@@ -164,20 +163,16 @@ class CachedProperty(property):
164163

165164
def __init__(self, func, doc=None):
166165
super(CachedProperty, self).__init__(fget=func, doc=doc)
167-
self.lock = threading.RLock()
166+
self._name = func.__name__
168167

169168
def __get__(self, obj, cls):
170169
if obj is None:
171170
return self
172-
name = self.fget.__name__
173171
obj_dict = obj.__dict__
174-
with self.lock:
175-
try:
176-
# Return cached result if it was computed before the lock was acquired
177-
return obj_dict[name]
178-
except KeyError:
179-
# Otherwise call the function, cache the result, and return it
180-
return obj_dict.setdefault(name, self.fget(obj))
172+
try:
173+
return obj_dict[self._name]
174+
except KeyError:
175+
return obj_dict.setdefault(self._name, self.fget(obj))
181176

182177

183178
def _as_array(src, shape):

0 commit comments

Comments
 (0)