carpedm20 / emoji

emoji terminal output for Python
Other
1.87k stars 273 forks source link

`emoji` taking ~5 minutes to load on Python 3.10.8 #274

Closed Iinksafe closed 11 months ago

Iinksafe commented 1 year ago

Hi there,

I've been using emoji in Python 3.8 and it loaded way faster than in Python 3.10 (it usually took around ~5 sec. to load) But now it takes around 3 to 5 minutes to load. Any solution?

Thank you, Link

Iinksafe commented 1 year ago

I believe it's because the file data_dict.py is too large so it takes way too much to load.

The line can be found at https://github.com/carpedm20/emoji/blob/master/emoji/unicode_codes/__init__.py#L1C44-L1C44 (line 1, emoji / emoji / unicode_codes / __init__.py)

cvzi commented 1 year ago

I guess you can remove the languages that you don't need from the dict in data_dict.py to make it smaller. This can be done by removing these lines: https://github.com/carpedm20/emoji/blob/master/utils/get_codes_from_unicode_emoji_data_files.py#L476-L486 and then running utils/get_codes_from_unicode_emoji_data_files.py > output.py and then replacing the dict in data_dict.py with the content of output.py

How/where are you running it that it takes so long? It only takes 30 milliseconds to import it on my old i5-6600 with Python 3.10.9

Iinksafe commented 11 months ago

Apologies for the delay.

It's the very first line of code which takes up to ~5 minutes, import emoji. I guess I should remove other non-English languages to improve load time.

I use Python 3.10.8 [GCC 11.3.0] on Linux, Ubuntu.

Thank you for your response. Link

Iinksafe commented 11 months ago

Update. get_codes_from_unicode_emoji_data_files.py does not exist on my filesystem somehow, even though emoji is installed (pip installed).

Iinksafe commented 11 months ago

Final Update. I used tracemalloc and enabled it. As a result, emoji took nearly ~5 minutes to load.

You can reproduce this issue by running the following lines:

>>> import tracemalloc
>>> tracemalloc.start()
>>> import emoji  # hangs here for ~5 minutes (because tracemalloc was started earlier)
>>> emoji.is_emoji('🐶')
True