Improve import time
char101 opened this issue · 1 comments
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.
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.