Defer SciPy and SymPy imports to cut `import spatialmath` time (~800 ms → ~150 ms)
Maintainer thường phản hồi trong vòng 1 ngày
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
- 68/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- performance, testing
Hướng nghiên cứu
Start by reading the top-level imports and mentioned methods in base/quaternions.py, spline.py, base/symbolic.py, and base/argcheck.py. Compare the import-time regression approach from #198, then verify that import spatialmath leaves neither scipy nor sympy in sys.modules while the affected feature and SymPy-supported paths still work.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Follow-up to #198, which deferred matplotlib.pyplot until something actually plots. Its description noted that scipy.interpolate and sympy cost about as much. They are now the main remaining costs of import spatialmath.
Where the time goes
Measured with python -X importtime -c "import spatialmath" on Python 3.12, macOS, Apple M1 (8 GB), warm cache. Cold-start times will be higher.
| Module | Cost | Imported by |
|---|---|---|
scipy.interpolate + scipy.spatial.transform |
~455 ms | base/quaternions.py:19, spline.py:14-15 (both at top level) |
sympy (when installed) |
~200 ms | base/symbolic.py:19, via base/argcheck.py |
matplotlib (no pyplot) |
~100 ms | geom2d.py:13 from matplotlib.path import Path. #198 kept this on purpose because Polygon2 needs it for its geometry |
numpy |
~40 ms | |
| Total | ~800 ms |
SciPy: nothing needs it at import time
base/quaternions.py: the only user isqrand(). When the angle is limited, it does inverse-CDF sampling through_generate_inv_cdf_sin_squared_interp(), which is already@lru_cache'd. Every user pays ~440 ms for this one option.qslerpand the rest of the module don't use SciPy. Fix: move the import into that function, and make the-> interpolate.interp1dannotation a string or put it underTYPE_CHECKING.spline.py:CubicSpline,RotationSpline,RotationandBSplineare only used inside methods. Fix: import them inside those methods.- Both must change. If only one does, the other still loads
scipy.interpolate. SciPy stays a hard dependency; only when it loads changes. - #129 (open) adds more top-level SciPy imports to
spline.py(scipy.optimize,splrep) and would need the same treatment.
SymPy: avoid importing it just to check types
SymPy is optional. base/symbolic.py imports it inside a try so that issymbol() can check for sympy.Expr. But if "sympy" not in sys.modules, no argument can possibly be a SymPy expression. So issymbol() can return False without importing SymPy, and only import it once the user has imported SymPy themselves. This is a separate change from the SciPy one because argcheck is on almost every code path, so it needs its own testing (including the :SymPy: supported paths).
Expected result
About 150 ms for import spatialmath, and none of SciPy or SymPy loaded until a feature actually uses them. A regression test along the lines of #198's could assert that neither scipy nor sympy is in sys.modules after import spatialmath.
- Ngôn ngữ chính
- Python
- Star
- 643
- Fork
- 102
- Merge trung bình
- 11 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 rai-opensource/spatialmath-python
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
rai-opensource/spatialmath-python#235 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
rai-opensource/spatialmath-python#32 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
rai-opensource/spatialmath-python#236 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Line3.isparallel()/__or__ still scale-dependent, like the distance() bug fixed in #224Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
rai-opensource/spatialmath-python#231 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 50/100
rai-opensource/spatialmath-python#177 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rai-opensource/spatialmath-python
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Harmony OPeNDAP SubSetter (HOSS) Geographic LARC_CLOUD PREFIRE_SAT2_AUX-SAT R01 production
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
nasa/harmony-autotester#245 ·
-
[FEATURE] - Add UTVD supportĐang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Deltares/imod-python#1928 ·
-
Độ khó 1/5 Dưới một 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
-
feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100