Skip to content

Commit 54d34f9

Browse files
committed
perf: shave a few more µs off of attribute access
1 parent f1105f0 commit 54d34f9

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

numba_cuda/numba/cuda/cudadrv/devices.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ class _DeviceContextManager(object):
7070

7171
def __init__(self, device):
7272
self._device = device
73-
74-
def get_primary_context(self, *args, **kwargs):
75-
"""This attribute is forwarded directly, to avoid the performance overhead of `__getattr__`."""
76-
return self._device.get_primary_context(*args, **kwargs)
73+
# Forwarded directly, to avoid the performance overhead of
74+
# `__getattr__` and method lookup for a commonly accessed method
75+
self.get_primary_context = self._device.get_primary_context
7776

7877
def __getattr__(self, item):
7978
return getattr(self._device, item)
@@ -83,7 +82,7 @@ def __enter__(self):
8382

8483
def __exit__(self, exc_type, exc_val, exc_tb):
8584
# this will verify that we are popping the right device context.
86-
self._device.get_primary_context().pop()
85+
self.get_primary_context().pop()
8786

8887
def __str__(self):
8988
return f"<Managed Device {self.id}>"

0 commit comments

Comments
 (0)