Repository navigation
Speed up --list-dsn, primarily on Python 3.15 - #2380
Merged
Merged
Conversation
* move utilities from dsn_aliases.py to a new dsn_utils.py (reading and merging multiple files) * support a None ClientFactory in cli_runner.py, deferring populating it until after main_list_dsn() may have been run * create common config utilities for finding the config files * make AES a Python 3.15 lazy-load in config.py, since it is not needed in most cases: _eg_ reading DSNs from ~/.myclirc * read the config independently in list_dsn.py, using the new common config utilities, sidestepping full instantiations/imports * pass a verbosity int to main_list_dsn() instead of a MyCli object This brings down the --list-dsn operation from ~0.4 seconds to ~0.1 seconds (measured using Python 3.15 on a Mac Studio M1). On Python 3.14 on the same machine, the result is very modestly better, from consistently longer than 0.4 seconds, to consistently shorter than 0.4 seconds. Motivation: "mycli --list-dsn" is invoked during dynamic shell completions. This change makes shell completions considerably more responsive and pleasant to use. Homebrew users are already on Python 3.15, and will gain the full improvement immediately. For other packagers, considerably more time will be needed. Future work or discussion: function-level imports could be used to defer loading many dependencies in Python interpreters prior to 3.15, though it would make the code considerably less tidy. Maybe this could be done selectively, for example just with the AES import. Notes: --help and --version were already very fast under Python 3.15. --checkup has not been optimized, but there is little need, since it will always take some time to contact PyPi during the checkup run.
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
dsn_aliases.pyto a newdsn_utils.py(reading and merging multiple files)NoneClientFactoryincli_runner.py, deferring populating it until aftermain_list_dsn()may have been runconfig.py, since it is not needed in most cases: eg reading DSNs from~/.myclirclist_dsn.py, using the new common config utilities, sidestepping full instantiations/importsverbosityinttomain_list_dsn()instead of aMyCliobjectThis brings down the
--list-dsnoperation from ~0.4 seconds to ~0.1 seconds (measured using Python 3.15 on a Mac Studio M1). On Python 3.14 on the same machine, the result is very modestly better, from consistently longer than 0.4 seconds, to consistently shorter than 0.4 seconds.Motivation:
mycli --list-dsnis invoked during dynamic shell completions. This change makes shell completions considerably more responsive and pleasant to use.Homebrew users are already on Python 3.15, and will gain the full improvement immediately. For other packagers, considerably more time will be needed.
Future work or discussion: function-level imports could be used to defer loading many dependencies in Python interpreters prior to 3.15, though it would make the code considerably less tidy. Maybe this could be done selectively, for example just with the AES import.
Notes:
--helpand--versionwere already very fast under Python 3.15.--checkuphas not been optimized, but there is little need, since it will always take some time to contact PyPi during the checkup run.Checklist
changelog.mdfile.mycli/AUTHORS.txtfile (or it's already there).