gaogaotiantian commented on PR #50327:
URL: https://github.com/apache/arrow/pull/50327#issuecomment-4860959014
I'm not an expert in Cython but curious about how `result.append()` works. I
think as long as `result` is not defined as a Cython `list`, `result.append`
still works as a pure Python object? In that case, each `append` would trigger
a dynamic attribute search and the list would be reallocated a few times during
appending.
It would be an interesting experiment to do a full-allocation for the list
before assigning the data, as we already know the length of the list. An extra
step forward is to declare the return value as a list in Cython so it can
optimize `setitem` even more.
Something like
```cython
cdef list result = [None] * n
cdef Py_ssize_t i
for i in range(n):
result[i] = ...
return result
```
For a long list this might push the performance even further.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]