reduce CLI startup overhead by importing less #1338

Open
opened 2011-01-27 04:18:07 +00:00 by davidsarah · 5 comments
davidsarah commented 2011-01-27 04:18:07 +00:00
Owner

bin/tahoe takes about 3.5 seconds to perform a trivial command (e.g. bin/tahoe --help) on my machine. Most of this overhead is due to importing dependencies: source:src/allmydata/init.py imports all of Tahoe's dependencies, in order to check their versions.

Just removing the calls to get_package_versions_and_locations() and check_all_requirements() does not work; we end up importing most of these libraries anyway. However, most of the CLI commands that do not start a node, should not need to import anything except twisted.python.usage.

By copying just the files that are needed for the CLI to work at all, and removing imports that are not really necessary, I was able to get the time to run bin/tahoe --help on my machine to 1.1 seconds, i.e. a factor-of-3 improvement. This is just a proof of concept at the moment, but I think this improvement could also be obtained for the real CLI. Note that just running a script that prints out the help text takes 0.8 seconds, due to the startup overhead of the Python interpreter.

Another major advantage of doing this is that the resulting CLI could be embedded as a library, without pulling in any of Tahoe's dependencies and their associated packaging woes.

`bin/tahoe` takes about 3.5 seconds to perform a trivial command (e.g. `bin/tahoe --help`) on my machine. Most of this overhead is due to importing dependencies: source:src/allmydata/*init*.py imports *all* of Tahoe's dependencies, in order to check their versions. Just removing the calls to `get_package_versions_and_locations()` and `check_all_requirements()` does not work; we end up importing most of these libraries anyway. However, most of the CLI commands that do not start a node, *should not* need to import anything except `twisted.python.usage`. By copying just the files that are needed for the CLI to work at all, and removing imports that are not really necessary, I was able to get the time to run `bin/tahoe --help` on my machine to 1.1 seconds, i.e. a factor-of-3 improvement. This is just a proof of concept at the moment, but I think this improvement could also be obtained for the real CLI. Note that just running a script that prints out the help text takes 0.8 seconds, due to the startup overhead of the Python interpreter. Another major advantage of doing this is that the resulting CLI could be embedded as a library, without pulling in any of Tahoe's dependencies and their associated packaging woes.
tahoe-lafs added the
code-frontend-cli
major
defect
1.8.1
labels 2011-01-27 04:18:07 +00:00
tahoe-lafs added this to the undecided milestone 2011-01-27 04:18:07 +00:00
davidsarah commented 2011-01-27 04:24:23 +00:00
Author
Owner

I was able to get the time to run bin/tahoe --help on my machine to 1.1 seconds...

I should clarify that this was actually python bin/tahoe.py --help, with PYTHONPATH set to the bin directory, and Twisted installed globally (for twisted.python.usage). But since the refactored CLI source files could be in a single directory and don't depend on anything else, it is possible to solve the path problem more simply than we are currently doing.

> I was able to get the time to run `bin/tahoe --help` on my machine to 1.1 seconds... I should clarify that this was actually `python bin/tahoe.py --help`, with PYTHONPATH set to the `bin` directory, and Twisted installed globally (for `twisted.python.usage`). But since the refactored CLI source files could be in a single directory and don't depend on anything else, it is possible to solve the path problem more simply than we are currently doing.
tahoe-lafs modified the milestone from undecided to 1.12.0 2015-02-02 13:48:48 +00:00

Milestone renamed

Milestone renamed
warner modified the milestone from 1.12.0 to 1.13.0 2016-03-22 05:02:25 +00:00

renaming milestone

renaming milestone
warner modified the milestone from 1.13.0 to 1.14.0 2016-06-28 18:17:14 +00:00

Moving open issues out of closed milestones.

Moving open issues out of closed milestones.
exarkun modified the milestone from 1.14.0 to 1.15.0 2020-06-30 14:45:13 +00:00
Owner

Ticket retargeted after milestone closed

Ticket retargeted after milestone closed
meejah modified the milestone from 1.15.0 to soon 2021-03-30 18:40:19 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: tahoe-lafs/trac-2024-07-25#1338
No description provided.