You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚡️ Speed up function check_project_configuration by 105% in PR #481 (saga4/doctor_cmd_check)
Here’s how you can make your program faster.
- Use a generator expression with `next()` to short-circuit and return immediately once a config file is found, instead of collecting all matches first.
- Avoid unnecessary list allocations for `found_configs` if you only need to check if any file exists and display their names.
- For speed, batch existence checks with a single loop, but short-circuit if only presence is needed. However, since the result prints all matches, collecting is still required.
- Remove broad `try:/except:` unless truly necessary, as reading filenames is very unlikely to fail and exception handling is expensive.
- Minimize repeated `str.join` calls.
Below is an optimized version that is faster, memory-friendly, and functionally identical.
**Summary of changes**.
- Replaced the `for` loop and manual list appending with a fast list comprehension.
- Removed unnecessary `try:/except:` block; catching `Exception` in this context is rarely helpful and slows the "happy path."
This will improve both performance and readability while delivering the same results.
0 commit comments