⚡️ Speed up function parse_uri_to_path by 19%
#75
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
parse_uri_to_pathinskyvern/forge/sdk/api/files.py⏱️ Runtime :
357 microseconds→299 microseconds(best of250runs)📝 Explanation and details
The optimized code achieves a 19% speedup by avoiding unnecessary URL decoding when no percent-encoded characters are present. The key optimization is adding a conditional check
if '%' in path:before calling the decoding function.What specific optimizations were applied:
unquote_to_bytes()followed by UTF-8 decoding instead ofunquote()for better performance when decoding is neededWhy this leads to speedup:
unquote()on every path, even when no decoding is neededunquote_to_bytes()+decode()is more efficient thanunquote()alonePerformance impact based on test results:
Impact on existing workloads:
The function is called from
download_file()when processingfile://URIs in local environments. Since file paths often don't contain percent-encoded characters, this optimization will provide consistent performance improvements for local file downloads without any behavioral changes.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-parse_uri_to_path-mi88p274and push.