⚡️ Speed up method S3DataSource.delete_object_tagging by 47%
#275
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.
📄 47% (0.47x) speedup for
S3DataSource.delete_object_tagginginbackend/python/app/sources/external/s3/s3.py⏱️ Runtime :
1.22 milliseconds→832 microseconds(best of274runs)📝 Explanation and details
The optimized code achieves a 46% runtime improvement (1.22ms → 832μs) and 1.9% throughput improvement through two key optimizations:
1. Non-blocking session retrieval with
asyncio.to_thread()self._session = self._s3_client.get_session()- synchronous call that blocks the event loopself._session = await asyncio.to_thread(self._s3_client.get_session)- runs the synchronous call in a thread poolThis prevents event loop blocking when
S3Client.get_session()performs synchronous operations (likely credential resolution or session initialization), allowing other async tasks to continue processing.2. Direct method call instead of
getattr()await getattr(s3_client, 'delete_object_tagging')(**kwargs)- dynamic attribute lookupawait s3_client.delete_object_tagging(**kwargs)- direct method callThis eliminates the overhead of runtime attribute resolution, reducing method invocation time.
Performance impact analysis:
delete_object_taggingmethod call becomes more efficient with direct invocation✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-S3DataSource.delete_object_tagging-mhcxm2dkand push.