⚡️ Speed up function get_default_chrome_location by 9%
#126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📄 9% (0.09x) speedup for
get_default_chrome_locationinskyvern/cli/browser.py⏱️ Runtime :
512 microseconds→471 microseconds(best of131runs)📝 Explanation and details
The optimization changes the
chrome_pathslist to a tuple in the Linux branch of the function. This simple change provides an 8% speedup by leveraging Python's more efficient tuple implementation.Key optimization:
chrome_paths = ["/usr/bin/google-chrome", "/usr/bin/chromium", "/usr/bin/chromium-browser"]tochrome_paths = ("/usr/bin/google-chrome", "/usr/bin/chromium", "/usr/bin/chromium-browser")Why this improves performance:
Impact on workloads:
Based on the function reference, this function is called from
setup_browser_config()during browser configuration setup. While not in a tight loop, the optimization provides measurable gains for:os.path.exists()callsTest case performance:
The optimization particularly benefits Linux-specific test cases:
Since the data structure is never modified (only iterated), using a tuple is semantically appropriate and provides free performance gains with zero behavioral changes.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-get_default_chrome_location-mirulto4and push.