[azure-ai-ml] Cache tenant id in JobOperations to speed up jobs.list() iteration - #48760
Open
saanikaguptamicrosoft wants to merge 3 commits into
Open
Conversation
…) iteration Fixes Azure#48415. _append_tid_to_studio_url called credential.get_token() on every job during list() iteration to decode the tenant id from a JWT. TokenCredential.get_token is not cached, so AzureCliCredential shelled out to 'az account get-access-token' per job (~77s for 100 jobs in the issue vs ~13s without). The tenant id is stable for a JobOperations instance, so cache it on self._tid_cache after the first decode and reuse for subsequent jobs. No public API or wire change.
saanikaguptamicrosoft
requested review from
Justin Firsching (JustinFirsching),
Klein Hu (NonStatic2014),
Amit Chauhan (achauhan-scc),
Arun (arunsu),
Jayesh Tanna (jayesh-tanna),
kingernupur,
Nikolay Rovinskiy (nick863),
Ayush Mishra (novaturient95),
Razvan Tanase (rtanase),
Riti Sharma (sharma-riti) and
Vivek Ramaswamy (vivram)
as code owners
August 26, 2026 10:26
|
Azure Pipelines: Successfully started running 1 pipeline(s). 9 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Caches the tenant ID in JobOperations to avoid repeated token acquisition during job-list iteration.
Changes:
- Reuses the decoded tenant ID per
JobOperationsinstance. - Documents the performance fix in the changelog.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
CHANGELOG.md |
Records the job-list performance fix. |
_job_operations.py |
Adds and applies the tenant ID cache. |
Addresses Copilot review feedback on PR: asserts _append_tid_to_studio_url populates both jobs' Studio URLs with the tenant id while credential.get_token() is called exactly once. Existing tests only covered the no-services no-op path.
Collapses the multi-line function signature and AccessToken constructor to single lines at the repo's 120-char line length, matching what black in the CI pipeline expects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #48415
_append_tid_to_studio_url was called for every job returned by MLClient.jobs.list() and decoded the tenant id from a fresh access token each time. TokenCredential.get_token is documented as non-caching, so AzureCliCredential shelled out to az account get-access-token per iteration. The issue reports ~77s for 100 jobs vs ~13s without this call.
The tenant id is stable for the lifetime of a JobOperations instance (self._credential is set once at construction). This change decodes it at most once per instance and reuses the cached value for subsequent jobs. No public API change, no wire change.
samples validation - Azure/azureml-examples#4114 (refer against main Azure/azureml-examples#4113)
Description
Please add an informative description that covers that changes made by the pull request and link all relevant issues.
If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines