New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PMEM: Optimization of enabled namespace methods #5873
Conversation
ut003460
commented
Feb 28, 2024
- Optimized the string connection section. Optimize repeated string concatenation operations into one-time concatenation instead of appending strings each time
- Replace subprocess.check_call with os.system to ensure that the code maintains its original functionality while improving execution efficiency to a certain extent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ut003460, thank you for this. I wrote a few comments here, but my main concern is about changing the process.system
to os.system
. Can you please provide me more info about why this change is needed, because maybe I am missing something here? Thank you
1. Optimized the string connection section. Optimize repeated string concatenation operations into one-time concatenation instead of appending strings each time 2. Replace subprocess.check_call with os.system to ensure that the code maintains its original functionality while improving execution efficiency to a certain extent Signed-off-by: ut003460 <xiongneng@uniontech.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ut003460 thank you for your updates. IMO, It is almost done. I just hove one small comment to docstring.
@@ -265,12 +265,10 @@ def enable_region(self, name="all"): | |||
def disable_namespace(self, namespace="all", region="", bus="", verbose=False): | |||
""" | |||
Disable namespaces | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please return the new lines into this docstring. It improves the readability, and it will be in respect to PEP 257
:param namespace: name of the namespace to be disabled | ||
:param region: Filter namespace by region | ||
:param bus: Filter namespace by bus | ||
:param verbose: Enable True command with debug information | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
if bus: | ||
args = f"{args} -b {bus}" | ||
args += f" -b {bus}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you're adding on operation here. Initially you have one "f string" operation (with two variables). Now you have both, one "f string" and a string concatenation.
I'm sorry but this is not an optimization.
Even worse, there's a consensus around the fact that usually string concatenations are slower than "f string" operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a very good optimization, thank you for your comment