- Package Name:
azure.ai.ml.MLClient -> azure.ai.ml.operations._job_operations._append_tid_to_studio_url
- Package Version: 1.34.1
- Operating System: linux
- Python Version: 3.12
Describe the bug
Iterating over azure.ai.ml.MLClient.jobs.list() is unnecessarily slow, since there's a full authentication flow initiated on every job item just to find out the tenant-id. The iteration repeatedly calls azure.ai.ml.operations._job_operations._append_tid_to_studio_url which has in it's implementation:
# Extract the tenant id from the credential using PyJWT
decode = jwt.decode(
self._credential.get_token(*default_scopes).token,
options={"verify_signature": False, "verify_aud": False},
)
tid = decode["tid"]
formatted_tid = TID_FMT.format(tid)
studio_endpoint.endpoint = studio_url + formatted_tid
As explicitly noted in the get_token function, this function does not cache any data.
To Reproduce
from azure.ai.ml import MLClient
from azure.identity import AzureCliCredential
ml_client = MLClient(
AzureCliCredential(),
subscription_id="foo",
workspace_name="bar",
resource_group_name="foobar",
)
# Load 100 jobs and exit
for index, job_run in enumerate(ml_client.jobs.list()):
if index > 100:
break
del job_run
Timing of the above with the vanilla-implementation in azure.ai.ml.operations._job_operations._append_tid_to_studio_url:
$ time python test.py
real 1m17.016s
user 0m55.264s
sys 0m7.458s
With the code-block in azure.ai.ml.operations._job_operations._append_tid_to_studio_url replaced with hard-coding my tenant-id:
time python test.py
real 0m13.239s
user 0m3.261s
sys 0m0.346s
Expected behavior
Looping over many jobs shouldn't be unnecessarily slow.
azure.ai.ml.MLClient->azure.ai.ml.operations._job_operations._append_tid_to_studio_urlDescribe the bug
Iterating over
azure.ai.ml.MLClient.jobs.list()is unnecessarily slow, since there's a full authentication flow initiated on everyjobitem just to find out the tenant-id. The iteration repeatedly callsazure.ai.ml.operations._job_operations._append_tid_to_studio_urlwhich has in it's implementation:As explicitly noted in the
get_tokenfunction, this function does not cache any data.To Reproduce
Timing of the above with the vanilla-implementation in
azure.ai.ml.operations._job_operations._append_tid_to_studio_url:With the code-block in
azure.ai.ml.operations._job_operations._append_tid_to_studio_urlreplaced with hard-coding my tenant-id:Expected behavior
Looping over many jobs shouldn't be unnecessarily slow.