Deserialization speedup proposal
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Lĩnh vực
- performance
Hướng nghiên cứu
Đọc các tệp được liên kết Example.msg, example_base.c, example.py, example_s.c và bench.py để hiểu cấu trúc C-extension được tạo theo đề xuất và benchmark. So sánh đề xuất đó với triển khai deserialization upstream, sau đó xác định liệu kiến trúc có chấp nhận được hay không và những bài kiểm thử cũng như phép đo hiệu năng nào sẽ xác định việc hoàn thành.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Feature request
Hello!
As already mentioned in other discussions python implementation has issues in serialization and deserialization performance(e.g. here). I focus on deserialization here.
I've tried some fixes on galactic branch and they look very promising for me: depending on message structure and size it's about 3-20 times faster. x3 for simple messages, up to x20 for complex types with high nesting level and array fields.
Feature description
The main idea is to avoid pure python code in message deserialization. To achieve it, every message is split into C extension base class and pure python derived class. C extension class contains all message fields, so deserialization method initializes C structure members without calling python methods. On the other hand pure python class contains all dunder methods and assertions.
Implementation considerations
Here is an example of how generated files look like for simple message file Example.msg:
_example_base.c extension module defines base class containing members of native types in lines 10-25.
Python module _example.py is the same as in upstream except for base class(line 62) and microoptimization of assertion in __init__ method(line 95).
Support extension module _example_s.c now uses specific subtype of PyObject(line 147), calls __new__ instead of __init__ to prevent pure python calls(line 170), directly initializes C typed fields of message(lines 188, 191) and creates nested collections (line 193-212).
Benchmark for this message which runs deserialization routine 1 million times gives 28 seconds vs 6,5 seconds
In case of more complex message like TestArrayComplex (from this issue) with 100 nested TestElement elements, the same benchmark gives 57,6 seconds vs 5,5 seconds for 50K deserializations.
I run benchmark with python3.8, ROS galactic, ubuntu 20.04, AMD 2,85GHz.
Pros:
- performance improvement
- public interface of message is not changed (as far as I can see)
Cons:
- binary dependency for basic message operations(creation, reading/writing fields).
- no more assertions while deserialization(I think it can be added)
- initialization logic is duplicated in
__init__and*_convert_to_pymethods. - compile time increased
I'm interested if this solution worth porting from my local galactic branch to upstream. Or may be it violates some ROS architecture principles.
- Ngôn ngữ chính
- EmberScript
- Star
- 26
- Fork
- 68
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không 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 ros2/rosidl_python
-
Eliminate array resetting loop in _msg_support.c.emCó thể đã có người làm @Lidang-Jiang đã nhận 167 ngày trước. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ros2/rosidl_python#255 · 1 reaction ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 56/100
ros2/rosidl_python#264 · 2 bình luận ·
-
Message named pkg/Duration with field builtin_interfaces/Duration is invalidCó thể đã có người làm @Lidang-Jiang đã nhận 167 ngày trước. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
ros2/rosidl_python#257 · 8 bình luận ·
-
enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
ros2/rosidl_python#242 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 32/100
ros2/rosidl_python#219 · 2 bình luận ·
Tất cả issue của ros2/rosidl_python
Issue tương tự
-
tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cofade/open-garden-planner#473 ·
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 74/100
hirobirofran/food-inventory-app#48 · 6 bình luận ·
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 76/100
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 76/100
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 76/100
swc-project/swc#12516 ·
Maintainer thường phản hồi trong vòng 1 ngày