⚡️ Speed up function setup_postgresql by 19%
#165
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.
📄 19% (0.19x) speedup for
setup_postgresqlinskyvern/cli/database.py⏱️ Runtime :
13.2 milliseconds→11.1 milliseconds(best of5runs)📝 Explanation and details
The optimization removes unnecessary console status management and replaces the unconditional 20-second sleep with an intelligent polling mechanism. Specifically:
Key changes:
is_postgres_running()function no longer manually callsstatus.stop()since Python's context manager automatically handles cleanup on exit, eliminating ~17ms of overhead from Rich UI operations.wait_for_postgres_container()function polls PostgreSQL readiness every second for up to 20 seconds, returning immediately when the container is ready instead of always waiting the full 20 seconds.Performance benefits:
Context impact:
Since
setup_postgresqlis called from the CLI initialization command (skyvern/cli/init_command.py), this optimization directly improves the developer experience during Skyvern's setup process. The function is in a critical path for first-time users, making the speedup valuable for onboarding workflows where reducing setup time enhances user satisfaction.The optimization is most effective for test cases involving local PostgreSQL detection and database validation, which are common operations during development and CI/CD pipeline setup.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-setup_postgresql-mjawrs7mand push.