⚡️ Speed up method SkyvernBrowserPage._input_text by 10%
#58
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.
📄 10% (0.10x) speedup for
SkyvernBrowserPage._input_textinskyvern/library/skyvern_browser_page.py⏱️ Runtime :
1.93 milliseconds→1.75 milliseconds(best of29runs)📝 Explanation and details
The optimization achieves a 10% runtime improvement by eliminating character-by-character typing overhead in the
input_sequentiallyfunction. The key change replaces the character iteration loop with bulk text input operations.What changed:
await locator.type(char, ...), short texts (≤ TEXT_PRESS_MAX_LENGTH) are now typed in one call withawait locator.type(text, ...).Why it's faster:
The original approach required 1,926 individual
await locator.type()calls (visible in line profiler), consuming 63.8% of the function's runtime. Each await involves async overhead, context switching, and browser communication. The optimized version reduces this to just 1-2 bulk operations, eliminating the loop entirely for most cases.Performance impact:
input_sequentiallyfunction dropped from 2.16ms to 0.48ms total timeReal-world benefits:
This optimization particularly benefits web automation workflows where text input is frequent, as it reduces the cumulative overhead of multiple small browser interactions into fewer, more efficient bulk operations. The 10% improvement compounds when
input_sequentiallyis called repeatedly during form filling or data entry tasks.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-SkyvernBrowserPage._input_text-mi6t7h6land push.