-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: lazily import our modules and external libraries (#624)
### Summary of Changes We depend on several large libraries that take a while to load. Previously, importing `Table` would already import almost all of them, leading to horrendous startup times: ``` (Measure-Command { python -c "from safeds.data.tabular.containers import Table" }).TotalSeconds ``` ➡️ 3.5068337 (seconds to import `Table` on main) Now, we lazily import our own modules in the `__init__.py` files, and we lazily import external libraries. The latter part is quite ugly, since each function must now contain their external imports at the start. There is no better solution, however, and the improvements are huge: ``` (Measure-Command { python -c "from safeds.data.tabular.containers import Table" }).TotalSeconds ``` ➡️ 0.1683219 (seconds to import `Table` in this branch) We still have to pay the cost for an import once we first import a module, but at least this no longer has to happen fully upfront. --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
e856cd5
commit 20fc313
Showing
56 changed files
with
800 additions
and
291 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import torch | ||
from torch.types import Device | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from torch.types import Device | ||
|
||
|
||
def _get_device() -> Device: | ||
import torch | ||
|
||
return torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.