Skip to content

Remove list_available_services from client creation happy path#3687

Open
SamRemis wants to merge 4 commits intoboto:developfrom
SamRemis:client-creation-perf-improvement
Open

Remove list_available_services from client creation happy path#3687
SamRemis wants to merge 4 commits intoboto:developfrom
SamRemis:client-creation-perf-improvement

Conversation

@SamRemis
Copy link
Copy Markdown
Contributor

Description of changes:
For all service creation, we have a cached list_available_services method that we call, but the output is only used if we encounter an error during client creation. This iterates through multiple directories to get all available service names, including the botocore/data directory with 424 seconds.

This PR removes the call to this method if the service is able to be found. Removing this step removes an average of 45.5ms for successful s3 client creation when run locally on my machine. The performance improvement of this will vary between machines.

import time
import statistics
import botocore.session

times = []
for _ in range(500):
    session = botocore.session.get_session()
    start = time.perf_counter()
    session.create_client('s3', region_name='us-east-1')
    times.append((time.perf_counter() - start) * 1000)

print(f"Average:     {statistics.mean(times):.1f}ms")
p95_index = int(len(times) * 0.95)
print(f"P95:      {sorted(times)[p95_index]:.1f}ms")

# Before:
# Average:     626.4ms
# P95:      838.0ms

# After:
# Average:     580.9ms
# P95:      778.4ms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 24, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.61%. Comparing base (ee748e4) to head (96865f1).
⚠️ Report is 154 commits behind head on develop.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3687      +/-   ##
===========================================
+ Coverage    92.59%   92.61%   +0.01%     
===========================================
  Files           68       68              
  Lines        15634    15698      +64     
===========================================
+ Hits         14477    14538      +61     
- Misses        1157     1160       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@jonathan343 jonathan343 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One edge I think we're breaking with this:

We currently have logic that catches an UnknownServiceError exception thrown when we attempt to load service endpoints and partitions files. In this case, we will fallback to using legacy endpoints.

Problem: If a customer has custom models (pre-EP2.0 migration) and supplies a api_version parameter, we'll start throwing a DataNotFoundError which isn't caught and we'll start breaking customers for this scenario.

botocore/botocore/client.py

Lines 125 to 137 in 61b379e

try:
endpoints_ruleset_data = self._load_service_endpoints_ruleset(
service_name, api_version
)
partition_data = self._loader.load_data('partitions')
except UnknownServiceError:
endpoints_ruleset_data = None
partition_data = None
logger.info(
'No endpoints ruleset found for service %s, falling back to '
'legacy endpoint routing.',
service_name,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants