[azure-core] Search for charset detection library at import time#43092
[azure-core] Search for charset detection library at import time#43092annatisch merged 8 commits intoAzure:mainfrom
Conversation
|
Thank you for your contribution @yuliy-openai! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the charset detection library import strategy in the AioHttpTransport class by moving import attempts from request-time to module-import-time, reducing syscall overhead for applications making frequent HTTP requests.
- Moves charset detection library imports (cchardet, chardet, charset_normalizer) from the
text()method to module-level - Creates a fallback
detectfunction that preserves the original error behavior when no charset libraries are available - Updates the CHANGELOG to document this performance fix
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| sdk/core/azure-core/azure/core/pipeline/transport/_aiohttp.py | Moves charset detection imports to module level and simplifies the text() method |
| sdk/core/azure-core/CHANGELOG.md | Documents the bug fix for repeated import attempts |
|
Thanks @yuliy-openai - could you please agree to the CLA policy above? |
I'm still chasing down our legal team for that :-( |
|
@microsoft-github-policy-service agree company="OpenAI" |
|
/check-enforcer override |
|
Thanks for your help and patience, @annatisch! |
|
You're welcome! Thank you for your contribution! |
Description
The
AioHttpTransportclass would try to import cchardet every time it got a request where it wanted to use charset detection on an http response. This requires syscalls to look for the module, which in the case of something which makes heavy use of, say, the Cosmos SDK, adds up to a lot of resource utilization. Doing it once is faster. I opted to keep the old behavior of erroring out only when this code is called.This was a regression from #21520
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines