Adjust the value in objects' insertion order array to the index - position.
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Currently, we store an array of bytes at the end of the inline value array of objects to record the insertion order.
This is expensive as we need to compute not only the value to insert, but where to insert it. Here's the code:
PyDictValues *values = _PyObject_InlineValues(owner_o);
Py_ssize_t index = value_ptr - values->values;
_PyDictValues_AddToInsertionOrder(values, index);
_PyObject_InlineValues requires some lookup, as it depends on tp->basicsize
return (PyDictValues *)((char *)obj + tp->tp_basicsize);
but it is _PyDictValues_AddToInsertionOrder that is the slowest:
int size = values->size;
uint8_t *array = (uint8_t *)&values->values[values->capacity];
array[size] = (uint8_t)ix;
values->size = size+1;
If instead of storing the delta of the index and position, instead of just the index, for the majority of objects the insert order array will go from { 0, 1, 2, 3, 4, ... } to { 0, 0, 0, 0, 0, ... }
And if the delta is zero, we don't need to store anything.
PyDictValues *values = _PyObject_InlineValues(owner_o);
Py_ssize_t index = value_ptr - values->values;
Py_ssize_t delta = index - values->size;
if (delta != 0) {
/* This is the expensive part */
_PyDictValues_AddToInsertionOrder(values, delta);
}
values->size++;
In the JIT we can track the size of the inline values, and know when delta will be zero. Reducing the above code to
values->size = KNOWN_SIZE;
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.
Hướng nghiên cứu
Bắt đầu bằng cách lần theo _PyObject_InlineValues và _PyDictValues_AddToInsertionOrder, sau đó kiểm tra đường dẫn JIT được mô tả trong issue để hiểu cách kích thước của các giá trị inline được theo dõi. Công việc được xem là hoàn tất khi bộ nhớ lưu trữ thứ tự chèn sử dụng hành vi zero-delta được đề xuất mà không thay đổi thứ tự đối tượng, và hành vi runtime bị ảnh hưởng vẫn chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- c, python
- Lĩnh vực
- backend, performance
- Loại issue
- Tái cấu trúc
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100