perf: skip the SDK import on custom-domain cache hits - #376
Draft
cloudsmith-iduffy wants to merge 2 commits into
Draft
perf: skip the SDK import on custom-domain cache hits#376cloudsmith-iduffy wants to merge 2 commits into
cloudsmith-iduffy wants to merge 2 commits into
Conversation
6 tasks
get_custom_domains() imported the cloudsmith_api SDK (~70ms) on every call. Import the API modules after the cache check, so only a cache miss pays that cost. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cloudsmith-iduffy
force-pushed
the
perf/defer-sdk-in-custom-domains
branch
from
August 21, 2026 23:40
fd29635 to
a848534
Compare
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.
Description
Skip the
cloudsmith_apiSDK import when the custom-domains cache is warm.credential_helpers/custom_domains.pyimportedcore.api.exceptions,core.api.initandcore.api.orgsat module level, which loads the full SDK. The docker/pnpm helpers import this module on every invocation, but the SDK is only needed on a custom-domains cache miss — at most once every 7 days per org. Move the three imports after the cache check.Results
Measured on macOS (M-series), Python 3.14.7,
PYTHONDONTWRITEBYTECODE=1(repo.envrcdefault). Baseline column = #375.credential-helper docker get(warm cache)Cumulative vs master: 2.94 s → 0.30 s (-90%).
Methodology (how to reproduce)
After perf: keep the SDK and requests out of startup #375, startup imports are clean, so profile the run phase in-process:
(Pipe
docker.cloudsmith.ioto stdin.) Top cost:credential_helpers/custom_domains.pymodule import at 141 ms — the deferred-until-runtime SDK chain from perf: keep the SDK and requests out of startup #375 resurfacing through this module. Second: the keyring backend detection at ~76 ms (see Additional Notes).Everything the three imports serve sits below the cache-hit early return in
get_custom_domains(), so deferring them changes no behaviour on any path.Regression guard:
test_startup_imports.pynow also probesimport cloudsmith_cli.credential_helpers.dockerin a subprocess and asserts nocloudsmith_api/requests/mcp/httpxmodule loads (written first, failed with the SDK loaded).test_credential_helper_install.pypatchedcustom_domains.list_custom_domains; the name no longer exists at module scope, so the patch target moves to the defining modulecore.api.orgs(the call-time import resolves through it).Type of Change
Flame graphs
Probe:
import cloudsmith_cli.cli.commands.credential_helper(what a docker helper invocation imports at run time). Icicle charts frompython -X importtime: parents above children, width = cumulative import time. Totals include the interpreter's ownsiteimports and vary a few ms between runs.Before:
After: