Defer docutils imports until help is rendered - #10551
Open
Adityaj0 wants to merge 1 commit into
Open
Conversation
``awscli.help`` imported ``docutils.core`` and the html4css1/manpage
writers at module scope, and ``awscli.topictags`` imported
``docutils.core``. Because ``awscli.customizations.commands`` subclasses
``HelpCommand``, that chain was pulled in during customization
registration on every CLI invocation -- including ``pygments`` and
``PIL`` via the docutils rst directives -- even for commands that never
render help. All of the uses are inside methods, so the imports move
into them.
Measured with 25 subprocess runs of ``aws --version`` per arm,
alternating between arms three times to control for drift:
before min 246-255ms
after min 232-240ms
so roughly 14ms (~6%) off every invocation. ``aws help``,
``aws s3 help``, ``aws ec2 describe-instances help`` and
``aws help topics`` were checked by hand, and ``TopicTagDB.scan`` still
parses topic files.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Aug 13, 2026
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.
Split out of #10545 at @aemous's request — this is half 1 of 2. The other half is #10552 (s3 filter precompilation); the two are independent and touch disjoint files.
awscli/help.pyimporteddocutils.coreand thehtml4css1/manpagewriters at module scope, andawscli/topictags.pyimporteddocutils.core. Becauseawscli/customizations/commands.pysubclassesHelpCommand, that whole chain was pulled in during customization registration on every CLI invocation — includingpygmentsandPILvia the docutils rst directives — even for commands that never render help.Every use is inside a method, so the imports move into them.
Measured with 25 subprocess runs of
aws --versionper arm, alternating between arms three times to control for machine drift:About 14ms (~6%) off every invocation. I'm quoting min-of-25 rather than the mean because run-to-run noise on this machine is ±20ms, which is larger than the effect — sequential (non-interleaved) runs initially suggested a bigger win than the interleaved A/B supports.
Checked by hand that help still renders:
aws help,aws s3 help,aws ec2 describe-instances help,aws help topics, andTopicTagDB.scanstill parses topic source files.Testing
tests/unit/test_help.py,tests/unit/test_topictags.py,tests/unit/test_clidriver.py,tests/functional/docs: 11967 passed, 3 skipped.ruffoutput on the touched files is unchanged from baseline.I did not run the full
tests/functionalsuite locally.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.