⚡️ Speed up function database_exists by 22%
#108
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.
📄 22% (0.22x) speedup for
database_existsinskyvern/cli/database.py⏱️ Runtime :
271 milliseconds→223 milliseconds(best of30runs)📝 Explanation and details
The optimization achieves a 21% speedup by combining two separate
console.print()calls into a single call during error handling in therun_commandfunction.Key optimization:
console.print()calls for error messages, the optimized version concatenates the messages with a newline and makes a single call toconsole.print().Why this improves performance:
The line profiler reveals that error handling dominated execution time in the original code - the two
console.print()statements consumed 92.7% of total runtime (53.2% + 39.5%). Eachconsole.print()call involves:By combining these into one call, the optimization eliminates the overhead of one complete formatting/I/O cycle.
Impact on workloads:
Based on the
function_references, this function is called extensively insetup_postgresql()for database connectivity checks and Docker container management. The optimization is particularly beneficial for:The test results confirm this - successful database checks see minimal improvement (0.1-2.6%), while error cases show significant gains (21-22%), making this optimization especially valuable when database connectivity issues occur during Skyvern's PostgreSQL setup process.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-database_exists-mir3paykand push.