Skip to content

Speed up --list-dsn, primarily on Python 3.15 - #2380

Merged
rolandwalker merged 1 commit into
mainfrom
RW/faster-dsn-alias-listing
Oct 17, 2026
Merged

rolandwalker merged 1 commit into
mainfrom
RW/faster-dsn-alias-listing

Conversation

@rolandwalker

Copy link
Copy Markdown
Contributor

Description

  • 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.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the mycli/AUTHORS.txt file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

 * 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.
@rolandwalker rolandwalker self-assigned this Oct 17, 2026
@rolandwalker
rolandwalker merged commit fb9ac6d into main Oct 17, 2026
13 checks passed
@rolandwalker
rolandwalker deleted the RW/faster-dsn-alias-listing branch October 17, 2026 14:03
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.

1 participant