PYPROGLIB Telegram 7097
🐍 Как ускорить Python в больших проектах: lazy imports в действии

Когда весь код живёт в одном монорепозитории и модули доступны отовсюду, количество импортов быстро превращается в тысячи.

Что начинает происходить со временем:
— скрипты стартуют по 30–40 секунд
— Jupyter-ноутбуки грузятся 10–15 минут
— распределённые jobs тратят больше времени на import, чем на сами вычисления

💡 Решение → Lazy imports
Модуль не загружается при import’е, а подменяется объектом LazyImport.

Настоящий импорт происходит только тогда, когда имя реально используется в коде:
from foo import bar

# globals() now contains {"bar": LazyImport("foo", "bar")}.
# the foo module has not yet been resolved or evaluated

qux = bar()

# in the evaluation of the above statement, bar is retrieved
# from the globals() dict, causing foo to be imported and bar
# to be reassigned to foo.bar


Что это даёт:
👌 мгновенный старт CLI-утилит
👌 быстрый запуск Jupyter даже с «тяжёлыми» внутренними библиотеками
👌 распределённые задачи не тратят время на лишние зависимости

→ Это не библиотека — это патч интерпретатора (форк CPython), но эффект огромный.

🔗 Полная статья (советуем сохранить)

🐸 Библиотека питониста

#буст
Please open Telegram to view this post
VIEW IN TELEGRAM
8👍4



tgoop.com/pyproglib/7097
Create:
Last Update:

🐍 Как ускорить Python в больших проектах: lazy imports в действии

Когда весь код живёт в одном монорепозитории и модули доступны отовсюду, количество импортов быстро превращается в тысячи.

Что начинает происходить со временем:
— скрипты стартуют по 30–40 секунд
— Jupyter-ноутбуки грузятся 10–15 минут
— распределённые jobs тратят больше времени на import, чем на сами вычисления

💡 Решение → Lazy imports
Модуль не загружается при import’е, а подменяется объектом LazyImport.

Настоящий импорт происходит только тогда, когда имя реально используется в коде:

from foo import bar

# globals() now contains {"bar": LazyImport("foo", "bar")}.
# the foo module has not yet been resolved or evaluated

qux = bar()

# in the evaluation of the above statement, bar is retrieved
# from the globals() dict, causing foo to be imported and bar
# to be reassigned to foo.bar


Что это даёт:
👌 мгновенный старт CLI-утилит
👌 быстрый запуск Jupyter даже с «тяжёлыми» внутренними библиотеками
👌 распределённые задачи не тратят время на лишние зависимости

→ Это не библиотека — это патч интерпретатора (форк CPython), но эффект огромный.

🔗 Полная статья (советуем сохранить)

🐸 Библиотека питониста

#буст

BY Библиотека питониста | Python, Django, Flask




Share with your friend now:
tgoop.com/pyproglib/7097

View MORE
Open in Telegram


Telegram News

Date: |

Telegram channels fall into two types: The visual aspect of channels is very critical. In fact, design is the first thing that a potential subscriber pays attention to, even though unconsciously. Find your optimal posting schedule and stick to it. The peak posting times include 8 am, 6 pm, and 8 pm on social media. Try to publish serious stuff in the morning and leave less demanding content later in the day. Telegram offers a powerful toolset that allows businesses to create and manage channels, groups, and bots to broadcast messages, engage in conversations, and offer reliable customer support via bots. During a meeting with the president of the Supreme Electoral Court (TSE) on June 6, Telegram's Vice President Ilya Perekopsky announced the initiatives. According to the executive, Brazil is the first country in the world where Telegram is introducing the features, which could be expanded to other countries facing threats to democracy through the dissemination of false content.
from us


Telegram Библиотека питониста | Python, Django, Flask
FROM American