flet icon indicating copy to clipboard operation
flet copied to clipboard

Migrate `colors` and `icons` to Enums

Open ndonkoHenri opened this issue 1 year ago • 0 comments

Discussed in https://github.com/flet-dev/flet/discussions/4160

Originally posted by Kenshin9977 October 14, 2024 While working on a project using flet I saw that any import made from flet took around 5 seconds. While investigating this I found out that 3 of those 5 seconds were used on import icons in flet_core/icons.py. The file defines ~8000 global variables in this fashion:

TEN_K = "ten_k"
TEN_K_SHARP = "ten_k_sharp"
TEN_K_ROUNDED = "ten_k_rounded"
TEN_K_OUTLINED = "ten_k_outlined"
TEN_MP = "ten_mp"
...
ZOOM_OUT_MAP = "zoom_out_map"
ZOOM_OUT_MAP_SHARP = "zoom_out_map_sharp"
ZOOM_OUT_MAP_ROUNDED = "zoom_out_map_rounded"
ZOOM_OUT_MAP_OUTLINED = "zoom_out_map_outlined"

icons_list = [v for k, v in vars().items() if k.isupper()]

I tested removing all of those lines and it effectively more than halved the time it takes to import flet and consequently my app's launch time. Of course, removing all these values isn't an option but using an enum, a dict, a seperate JSON or even put those in several optional packages are ideas to radically improve flet's import time.

ndonkoHenri avatar Oct 15 '24 18:10 ndonkoHenri