⚡️ Speed up method AwsEnvironment.get_session by 6%
#85
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.
📄 6% (0.06x) speedup for
AwsEnvironment.get_sessioninwandb/sdk/launch/environment/aws_environment.py⏱️ Runtime :
41.5 seconds→39.1 seconds(best of6runs)📝 Explanation and details
Optimizations Applied:
asyncio.to_thread(): Replaced the customevent_loop_thread_exec()wrapper with nativeasyncio.to_thread()for running theboto3.Sessionconstructor in a thread. This results in slightly better performance and clarity, avoids redundant lambda wrapping and future management, and is recommended for Python 3.9+ when calling blocking functions from async code.asyncio.to_thread()instead of wrapping the function with another async function call, slightly improving memory efficiency and reducing context switches by removing the wrapper overhead.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-AwsEnvironment.get_session-mhe4gjoland push.