Skip to content

Commit

Permalink
perf: avoid cross_validation_lock context manager
Browse files Browse the repository at this point in the history
this has a runtime overhead (about 20% faster without it)
  • Loading branch information
maartenbreddels committed Sep 14, 2022
1 parent aa23cc0 commit ef4d638
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion traitlets/traitlets.py
Expand Up @@ -654,8 +654,14 @@ def get(self, obj, cls=None):
DeprecationWarning,
stacklevel=2,
)
with obj.cross_validation_lock:
# Using a context manager has a large runtime overhead, so we
# write out the obj.cross_validation_lock call here.
_cross_validation_lock = obj._cross_validation_lock
try:
obj._cross_validation_lock = True
value = self._validate(obj, default)
finally:
obj._cross_validation_lock = _cross_validation_lock
obj._trait_values[self.name] = value
obj._notify_observers(
Bunch(
Expand Down

0 comments on commit ef4d638

Please sign in to comment.