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

Improve import time #31

Open
char101 opened this issue Dec 16, 2023 · 1 comment
Open

Improve import time #31

char101 opened this issue Dec 16, 2023 · 1 comment

Comments

@char101
Copy link

char101 commented Dec 16, 2023

Hi,

I am profiling my application startup time. In the profile result, jurigged requires around 300ms, where 200ms comes from importing blessed. Since I only run live.watch() and blessed is only used to print terminal colors, this 200ms seems too much.

May I suggest using more lightweight library to print terminal colors in the live module (e.g. colorama), with a wrapper class

import colorama

class Terminal:
    def __init__(self):
        if sys.platform == 'win32':
            colorama.just_fix_windows_console()

    def __getattr__(self, name):
        styles = []
        for s in name.split('_'):
            match s:
                case 'bold':
                    styles.append(colorama.Style.BRIGHT)
                case other:
                    styles.append(getattr(colorama.Fore, other.upper()))
        return lambda text: ''.join(styles) + text + colorama.Style.RESET_ALL

T = Terminal()

I have added this to live.py and the import time is reduced to around 100ms.

@JamesHutchison
Copy link

Maybe a separate ticket, but the load time can be 100%+ slower with jurigged. This makes the use of the library a bit of a trade-off which I think negatively affects adoption.

For example, your baseline takes 1 minute to load something. You want to test a single thing, which you expect to pass. With jurigged, it takes 2 minutes. Now, when you test it, if it passes, you would have saved time to skip jurigged. If it fails, but you see the only bug and fix it, then on retest you're at 2 minutes which is no better than jurigged.

Likewise, if things get into a bad state with jurigged, you're restarting and taking that penalty again.

In regards to terminal colors, I think its worth revisiting how logging is done as swapping the logger meant I lost the colors.

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

No branches or pull requests

2 participants