perf: defer the rich, urllib3 and semver imports - #377
Draft
cloudsmith-iduffy wants to merge 2 commits into
Draft
Conversation
This was referenced Aug 21, 2026
Import rich in rich_print_table, semver in the version parsers, and move the urllib3 insecure-request warning filter to core/session.py, which every insecure request flows through. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cloudsmith-iduffy
force-pushed
the
perf/trim-remaining-eager-imports
branch
from
August 21, 2026 23:40
1447df4 to
2460f0e
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
Defer the last eager imports:
rich,urllib3andsemver.cli/utils.pyimportedrich.console/rich.table(~35 ms) at module level; onlyrich_print_tableuses them.cloudsmith_cli/__init__.pyimportedurllib3(~20 ms with itshttp.clientchain) only to install theInsecureRequestWarningfilter. The filter moves tocore/session.py: every insecure request (-S/--without-api-ssl-verify) flows through a session from that module, so the filter is installed before any request can warn.core/version.pyandcore/api/version.pyimportedsemver(~6 ms) at module level; only the version parsers use it.Results
Measured on macOS (M-series), Python 3.14.7,
PYTHONDONTWRITEBYTECODE=1(repo.envrcdefault). Baseline column = #376.cloudsmith --versioncredential-helper docker get-X importtime)site)Series summary (vs master)
cloudsmith --versioncredential-helper docker get-X importtimetotal)With warm bytecode caches (end-user installs; the dev
.envrcsetsPYTHONDONTWRITEBYTECODE=1which roughly triples the numbers): docker helper 0.80 s → ~0.10 s.Methodology (how to reproduce)
python -X importtime -m cloudsmith_cli --version 2>&1 | sort -t'|' -k2 -n | tail -25after perf: skip the SDK import on custom-domain cache hits #376 showed three chains left:rich.console <- cli.utils <- cli.config <- decorators,urllib3 <- cloudsmith_cli(package__init__), andsemver <- core.api.version <- commands.main.rgfor call sites), then defer.HEAVY_PREFIXESincli/tests/test_startup_imports.pynow includesrich,urllib3andsemver.Type of Change
Additional Notes
urllib3.disable_warningsnow runs whencore/session.pyis imported, which happens before any session (and therefore any insecure request) exists.Flame graphs
Probe:
cloudsmith --version. 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: