viirya commented on PR #50327:
URL: https://github.com/apache/arrow/pull/50327#issuecomment-4861214624

   Good question — Cython already knows. Its type inference marks `result = []` 
as `list`, so the untyped version and an explicit `cdef list result = []` 
compile to the *identical* generated C: both lower `result.append(x)` to 
Cython's inlined `__Pyx_PyList_Append()`, which appends in place via 
`PyList_SET_ITEM` while there's spare capacity and only falls back to 
`PyList_Append` (geometric resize) otherwise. I verified by cythonizing both 
variants side by side and diffing the generated C — the loop bodies are 
byte-identical. That's indeed why the `append` form is already fast, and why 
adding `cdef list` doesn't move the numbers.
   


-- 
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]

Reply via email to