mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[jit][perf] Reduce lookupInModule overhead. (#119145)
It's inefficient to split remaining parts of the module name by '.' just to join it back again. Instead it's more idiomatic and efficient to use `maxsplit=1` to ensure that all remaining parts remain intact. This improves best case time and space complexity since scan can terminate on first encountered `.` and only 2 parts are returned in a list. Pull Request resolved: https://github.com/pytorch/pytorch/pull/119145 Approved by: https://github.com/Skylion007
This commit is contained in:
committed by
PyTorch MergeBot
parent
fa8d97776c
commit
124a54ef16
@ -105,9 +105,7 @@ def createResolutionCallbackFromEnv(lookup_base):
|
||||
|
||||
def lookupInModule(qualified_name, module):
|
||||
if "." in qualified_name:
|
||||
parts = qualified_name.split(".")
|
||||
base = parts[0]
|
||||
remaining_pieces = ".".join(parts[1:])
|
||||
base, remaining_pieces = qualified_name.split(".", maxsplit=1)
|
||||
module_value = getattr(module, base)
|
||||
return lookupInModule(remaining_pieces, module_value)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user