Importing open_meteo takes about 4.5 seconds since 1.0.0
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 28/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- performance
Hướng nghiên cứu
Start by reading the shared model base class and forecast.py, where import profiling shows most of the delay. The proposed lazy_compilation approach is measured, but it currently fails with real freezegun until the reported mashumaro fix is released. After that dependency fix is available, check parsing under freeze_time and compare import time and parsing results with the existing behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Update (3 December): all numbers below are re-measured on an idle machine with the same versions and settings; the first ones were about 2.5× higher, most likely because the machine was busy. The ratios and the proposal are unchanged.
Since 1.0.0, import open_meteo takes about 4.5 seconds on our machine. Almost all of it is mashumaro building the from_dict/to_dict code of every model when the classes are created: the models grew from about 630 lines in 0.4.0 to about 3,700 in 1.0.1, and forecast.py alone takes about 3.1 s.
In Home Assistant this shows at every start: integrations are imported one after another, so others wait behind it.
Measured (python 3.14, mashumaro 3.23, the Home Assistant 2026.12.0 image, 1 CPU, python -X importtime -c "import open_meteo", 3 runs each):
| import | |
|---|---|
| 0.4.0 | 1.2-1.3 s |
| 1.0.1 | 4.6-4.7 s |
1.0.1 with lazy_compilation (below) |
0.7-0.9 s |
cProfile of the import: 55 calls to mashumaro's __init_subclass__ account for nearly all of it; about 60 % builds the unpack code and 40 % the pack code.
A possible fix: mashumaro's lazy_compilation, set once on a shared base class of the models, so a model's code is built when it is first used. I tried it locally:
- The test suite passes unchanged (147 passed, 23 snapshots), including
test_parsing_with_patched_datetime, and so do Home Assistant's open_meteo tests (16 passed). - Every fixture parses to the same result as with 1.0.1 (to_dict compared for all 36 fixtures that map to a model).
- The cost moves to the first parse of a model: about 0.6 s for the first
Forecast(Home Assistant'sforecast.jsontest fixture) instead of under 10 ms, then about 1 ms. Only the models a caller actually uses are built. For an async caller that first parse runs on the event loop; a caller can warm up in an executor by parsing a small response once.
One catch: with real freezegun, a first parse inside freeze_time fails (UnserializableField: Field "time" of type datetime in CurrentForecast is not serializable), where it works today. That is a mashumaro bug in lazy compilation, which I reported as Fatal1ty/mashumaro#391 with a fix ready. test_parsing_with_patched_datetime still passes with the patch, so it does not catch this case. So a PR here would wait for a mashumaro release with that fix.
Would you accept a PR for this once that is out? Or would you rather keep building at import (for example to keep the first parse fast) and look for another way?
Version
1.0.1
Additional information
This analysis and the patch were made with Claude Opus 5.5 (claude-opus-5-5), an AI model; I reviewed them myself. Careful review and measurements on other machines are very welcome.
- Ngôn ngữ chính
- Python
- Star
- 32
- Fork
- 10
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của frenck/python-open-meteo
-
Dependency DashboardĐang mởno-stale
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
frenck/python-open-meteo#413 ·
Tất cả issue của frenck/python-open-meteo
Issue tương tự
-
docs(contributing): the two things that silently block a PRCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởavailable documentation good first issue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 95/100
Nixitov/Riptide-Native#944 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
JTHCode/secretguard#24 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: middleware documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainer thường phản hồi trong vòng 1 ngày