Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused imports for faster initial navigation #411

Closed
wants to merge 2 commits into from

Conversation

jdlcdl
Copy link

@jdlcdl jdlcdl commented Jul 22, 2023

SUPERCEDED BY #416

Since commit 94abdd3 there is a noticeable delay after boot/restart moving from the MainMenu to Seeds or Tools. That commit does not look suspicious, but I suspect it is the result of a history-rewriting --rebase on the flow_tests commit which followed it.

I have yet to identify exactly which changes created this delay.

In the meantime, I've tried importing slow-to-load modules from the controller so that navigation is much faster once the main menu has loaded. If there is a cleaner way to do this, I'm game. Otherwise, these unused modules are bound to a name 'unused' that is then deleted imported w/o local binding. I've opted to target the camera as it's the slowest, then the heaviest of screens ordered by heaviest-first, to avoid circular imports like would happen with views; my choices based on a threshold of 0.1 seconds on a pi2.

This does result in a slightly slower boot and splash.
pi0 boots to splash in 19s, to main menu after 25s...

@jdlcdl jdlcdl marked this pull request as draft July 22, 2023 20:33
@jdlcdl
Copy link
Author

jdlcdl commented Jul 23, 2023

I use a pi2 for development, which is quite a bit faster than the pi0.

Here is a script and some timings around this code which "costs time" loading in the Controller for the benefit of "saving time" as user moves from the initial MainMenu to Seeds or Tools.

from time import time
from importlib import import_module

import seedsigner.hardware.buttons # slowly imports GPIO along the way

def time_import(module_name):
    last = time()
    import_module(module_name)
    print(time() - last, module_name)

# 1.287 seconds on pi2
time_import('seedsigner.hardware.camera')

# 0.742 seconds on pi2
time_import('seedsigner.gui.screens.scan_screens')

# 0.265 seconds on pi2.
time_import('seedsigner.gui.screens.seed_screens')

# 0.102 seconds on pi2.
time_import('seedsigner.gui.screens.tools_screens')

@jdlcdl jdlcdl marked this pull request as ready for review July 23, 2023 10:32
@kdmukai
Copy link
Contributor

kdmukai commented Jul 23, 2023

Pi Zero:

>>> # 1.287 seconds on pi2 -> 2.550 on pi0
>>> time_import('seedsigner.hardware.camera')

>>> # 0.742 seconds on pi2 -> 0.916 on pi0
>>> time_import('seedsigner.gui.screens.scan_screens')

>>> # 0.265 seconds on pi2 -> 0.613 on pi0
>>> time_import('seedsigner.gui.screens.seed_screens')

>>> # 0.102 seconds on pi2 -> 0.273 on pi0
>>> time_import('seedsigner.gui.screens.tools_screens')

@jdlcdl jdlcdl marked this pull request as draft July 30, 2023 09:36
@jdlcdl
Copy link
Author

jdlcdl commented Jul 30, 2023

PR #416 is where it's at!!!

@jdlcdl jdlcdl closed this Jul 30, 2023
@jdlcdl jdlcdl deleted the load_imports_faster branch August 9, 2023 08:39
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.

2 participants