Skip to content

Commit

Permalink
[Mellanox] optimize platform API import time (#10815)
Browse files Browse the repository at this point in the history
- Why I did it
"import sonic_platform" takes about 600ms ~ 1000ms, it is kind of slow. After this optimization, the time is about 100ms. The benefit is that those CLIs which does not need the slow import sentence would be faster than before.

- How I did it
Find slow import and call them when need.

- How to verify it
Measure the import time.
  • Loading branch information
Junchao-Mellanox authored Jun 7, 2022
1 parent 5c86949 commit f135f37
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

from . import utils
from .device_data import DeviceDataManager
from .sfp import SFP, deinitialize_sdk_handle
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

Expand Down Expand Up @@ -113,8 +112,10 @@ def __del__(self):
if self.sfp_event:
self.sfp_event.deinitialize()

if SFP.shared_sdk_handle:
deinitialize_sdk_handle(SFP.shared_sdk_handle)
if self._sfp_list:
from .sfp import SFP, deinitialize_sdk_handle
if SFP.shared_sdk_handle:
deinitialize_sdk_handle(SFP.shared_sdk_handle)

##############################################
# PSU methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import glob
import os
from sonic_py_common import device_info

from . import utils

Expand Down Expand Up @@ -173,6 +172,7 @@ class DeviceDataManager:
@classmethod
@utils.read_only_cache()
def get_platform_name(cls):
from sonic_py_common import device_info
return device_info.get_platform()

@classmethod
Expand Down

0 comments on commit f135f37

Please sign in to comment.