Repository navigation
Skip the full service scan when loading a known service model - #3822
Open
jonathan343 wants to merge 1 commit into
Open
jonathan343 wants to merge 1 commit into
jonathan343 wants to merge 1 commit into
Conversation
load_service_model no longer lists every available service to confirm a service exists, cutting filesystem calls for a cold s3 load from ~5,600 to 70. Unknown names still fall back to the full listing.
jonathan343
marked this pull request as ready for review
October 13, 2026 00:58
arandito
reviewed
Oct 13, 2026
| service_name=service_name, | ||
| known_service_names=', '.join(known_services), | ||
| ) | ||
| if not self._is_known_service(service_name, type_name): |
Contributor
There was a problem hiding this comment.
Before, the result of list_available_services was cached per model type. So subsequent model loads after the first client in a session would be fast.
However, _is_known_service lists the entire data directory every time a model is loaded without caching it. The first client is faster, but subsequent clients now slow down.
I confirmed this locally by creating a client for each service we support and it took about ~1ms more per new client (Macbook M3 Pro, 3.14). This was the mean amongst all 400+ though, the first couple clients in the iteration saw +2ms.
Something to confirm to see if we need to cache the listdir result.
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.
Summary
Every
create_clientcall goes throughLoader.load_service_model, which first checks that the service exists by callinglist_available_services(type_name). That call walks every service directory on the search path (437 services) looking for a matching file likeservice-2.jsonfor a specific service. The result is cached per type, butcreate_clientneeds two types,service-2andendpoint-rule-set-1. So the first client in each session does two full scans, which is roughly 16 of the 33 ms it takes to create an S3 client. Short-lived processes that only create a client or two pay that cost on every run.With this change, the loader looks in the requested service's own directory first. Names still have to match a directory name exactly, so
S3,s3/, andec2/../s3are still rejected. If the service isn't there, the loader falls back to the full scan, so an unknown name raises the sameUnknownServiceError, with the same list of valid names, as before.Before / After
I ran this script from the repo root on
developand on this branch:Before (
develop):After:
Client creation takes about half as long, and the directory listings drop from 878 to 6. Both ran locally on an Apple M5 Max with Python 3.12. Across five runs on each side, the times varied by less than 1.5 ms.
Additional Testing
I also compared
load_service_modelresults betweendevelopand this branch for every bundled service, usingservice-2,paginators-1, andwaiters-2, plus a few odd names likeS3,s3/, andec2/../s3. The loaded models and error messages were identical in every case. This was a local check, not part of CI.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.